2.1 php语言基础
2.1.1 php文件格式
helloworld.php
hello world!
2.1.2 php标记
……?>
echo (script书写方法!);
echo(这是asp的标记输出);
%>
echo(这是php的的简写标记输出);
?>
这是真的!
这是假的!
2.1.3 php 文件爱女的访问形式
php为服务端执行的语言,必须通过服务器解释才能执行
hello world!
hello world!
2.1.4 php程序注释
2.1.5 php语法概述
类似于c/c++
2.2 php的变量
2.2.1 php的变量命名
php变量名是区分大小写的,和c语言是一致的;
变量名必须是以美元符号($)开始;
变量名开头可以以下划线开始;
变量名不能以数字字符开始。
2.2.2 php的数据类型
$single_str='我被单引号括起来了!
';
echo $single_str;
$single_str='输出单引号:\'嘿嘿,我在单引号里面\'
';
echo $single_str;
$single_str='输出双引号:我在双引号里面
';
print $single_str;
$single_str='输双美元符号:$';
print $single_str;
?>
$double_str=我被双引号括起来了!
;
echo $single_str;
$single_str=输出单引号:'嘿嘿,我在单引号里面'
; //不需要转义符
echo $single_str;
$single_str=输出双引号:\我在双引号里面\
; //需要转义符
print $single_str;
$single_str=输出美元符号:\$
; //需要转义符
print $single_str;
$single_str=输出反斜杠:\\
; //需要转义符
print $single_str;
?>
$heredoc_str =
你好
美元符号 $
反斜杠 \
我爱你
'我恨你'
heredoc_mark;
echo $heredoc_str;
?>
本实例演示字符串中对变量的引用:
2.2.3 数据类型转换
2.2.4 php中的预订义变量
2.2.5 变量的引用
2.2.6 变量的变量
2.2.7 常量
2.3 php的运算符
2.3.1 算术运算符
2.3.2 赋值运算符
2.3.3 位运算符
2.3.4 三元运算符
2.3.5 比较运算符
10)?true:false) .
);
echo(10大于等于吗: . ((10>=10)?true:false) .
);
echo(10等于吗: . ((10==10)?true:false) .
);
echo(10不等于吗: . ((10!=10)?true:false) .
);
?>
2.3.6 字符串运算符
2.3.7 递增和递减运算符
2.3.8 逻辑运算符
2.3.9 运算符优先级
2.4 表达式
2.5 控制语句
2.5.1 条件语句
=60 && $achievement
echo 你刚刚及格了;
elseif ($achievement>=70 && $achievement
echo 你得了良好;
elseif ($achievement>=80 && $achievement
echo 你很优秀哦!;
else
echo 你兼职太棒了!
?>
2.5.2 循环语句
10) {
break;
}
print $i. -;
}
;
/* 应用,省略个表达式*/
$i = 1;
for (;;) {
if ($i > 10) {
break;
}
print $i. -;
$i++;
}
;
/* 应用*/
for ($i = 1; $i
;
/* 应用 */
for ($i = 1; $i
?>
10) break;
endwhile;
?>
2.5.3 break和continue语句
2.6 数组
2.6.1 数组类型
枚举数组
关联数组
多维数组
array(name=>james,sex=>male,age=>28),
1=>array(name=>john,sex=>male,age=>25),
2=>array(name=>susan,sex=>female,age=>24));
print $student[2][age]
?>
2.6.2 数组初始化
使用数组标识符
2.6.3 数组的应用
$value) {
unset($array[$i]);
}
print_r($array);
echo
;
// 添加一个单元(注意新的键名是5,而不是你可能以为的0)
$array[] = 6;
print_r($array);
// 重新索引:
$array = array_values($array);
$array[] = 7;
print_r($array);
?>
2.7 函数
2.7.1 内置函数
2.7.2 自定义函数
2.7.3 函数变量的作用域
2.8 日期和时间处理
2.8.1 获取日期和时间
2.8.2 使用getdate函数获得日期信息
2.8.3 使用mktime函数取得一个日期的时间戳
