<?php
class Car {
//增加构造函数与析构函数
function __construct(){
print "construct \n";
}
function __destruct(){
print "destruct \n";
}
}
$car = new Car();
class Car {
//增加构造函数与析构函数
function __construct(){
print "construct \n";
}
function __destruct(){
print "destruct \n";
}
}
$car = new Car();
2015-07-21
<?php
class Car {
public $speed = 0;
//增加speedUp方法,使speed加10
public function speedUp(){
return $this->speed+=10;
}
}
$car = new Car();
$car->speedUp();
echo $car->speed;
class Car {
public $speed = 0;
//增加speedUp方法,使speed加10
public function speedUp(){
return $this->speed+=10;
}
}
$car = new Car();
$car->speedUp();
echo $car->speed;
2015-07-21
<?php
class Car{
//在这里定义一个共有属性name
public $name = 'name';
}
$car = new Car();
//在这里输出$car对象的name属性
echo $car->name;
class Car{
//在这里定义一个共有属性name
public $name = 'name';
}
$car = new Car();
//在这里输出$car对象的name属性
echo $car->name;
2015-07-21
//定义方法
public function getName() {
//方法内部可以使用$this伪变量调用对象的属性或者方法
return $this->name;
public function getName() {
//方法内部可以使用$this伪变量调用对象的属性或者方法
return $this->name;
2015-07-21
PHP写文件也具有两种方式,最简单的方式是采用file_put_contents。
$filename = './test.txt';
$data = 'test';
file_put_contents($filename, $data);
采用fwrite进行文件写入。
$fp = fopen('./test.txt', 'w');
fwrite($fp, 'hello');
fwrite($fp, 'world');
fclose($fp);
$filename = './test.txt';
$data = 'test';
file_put_contents($filename, $data);
采用fwrite进行文件写入。
$fp = fopen('./test.txt', 'w');
fwrite($fp, 'hello');
fwrite($fp, 'world');
fclose($fp);
2015-07-20
<?php
//获取字符串长度
$love =' I love you ';
$len = strlen($love);
echo $len . "<br>";
echo trim($love)."<br>";
echo $len. "<br>";
echo rtrim($love)."<br>";
echo $len . "<br>";
echo ltrim($love)."<br>";
echo $len . "<br>";
?>
运行结果
14
I love you
14
I love you
14
I love you
14
空格没去掉吗?难道
//获取字符串长度
$love =' I love you ';
$len = strlen($love);
echo $len . "<br>";
echo trim($love)."<br>";
echo $len. "<br>";
echo rtrim($love)."<br>";
echo $len . "<br>";
echo ltrim($love)."<br>";
echo $len . "<br>";
?>
运行结果
14
I love you
14
I love you
14
I love you
14
空格没去掉吗?难道
2015-07-18