123456789101112131415161718192021<?php class Car{ public $color; public $model; public function __construct($color, $model){ $this -> color = $color; $this -> model = $model; } public function message(){ return "My car is a".$this -> color."".$this -> model."!";#注意要加分号! }}#上面完成了对类的定义!$myCar = new Car("black", "Volvo");#实例化类,对其对象赋值;echo $myCar -> message();#调用myCar类中的对象message()echo "<br>";$myCar = new Car("red", "Toyota");echo $myCar -> message();?> 1234<?php echo strlen("Hello,world");?> 123<?phpecho str_word_count("hello world");?>php 123<?phpecho strrev("hello world");?> strrev()用来反转字符。 1 12<?phpecho strpos("hello world", "world");#意思是在后面的字符中找前面的字符,并将匹配部分输出 123<?phpecho str_replace("hello", "Dolly", "hello world");?>