1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?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();
?>

1
2
3
4
<?php
echo strlen("Hello,world");
?>

1
2
3
<?php
echo str_word_count("hello world");
?>php

1
2
3
<?php
echo strrev("hello world");
?>

strrev()用来反转字符。

1

1
2
<?php
echo strpos("hello world", "world");#意思是在后面的字符中找前面的字符,并将匹配部分输出
1
2
3
<?php
echo str_replace("hello", "Dolly", "hello world");
?>