一、基本语法
(1)PHP标记
<?php echo "Hello World!"; // 当文件为纯PHP时,最好在末尾删除PHP结束标记 //?>
(2)从HTML中分离
// 在一对开始和结束之外的内容,都会被PHP解释器忽略。也就是html标签和PHP代码混合的那种,跟jsp,asp一样... <p>This is going to be ignored by PHP and displayed by the browser.</p> <?php echo ‘While this is going to be parsed.‘; ?> <p>This will also be ignored by PHP and displayed by the browser.</p> // 使用条件,高级分离 <?php if ($expression == true): ?> This will show if the expression is true. <?php else: ?> Otherwise this will show. <?php endif; ?>
(3)指令分隔符,注释
PHP需要在每个语句后面用分隔符结束指令。
注释: // 或 /* ... */ 但是,*/ 会匹配最近的那个,切记!切记!
二、类型
PHP支持8种原始数据类型。
四种标量类型:boolean(布尔型),integer(整型),float(浮点型,double),string(字符串)
两种复合类型:array(数组),object(对象)
两种特殊类型:resource(资源),NULL(无类型)
<?php
$a_bool = TRUE; // a boolean
$a_str = "foo"; // a string
$a_str2 = ‘foo‘; // a string
$an_int = 12; // an integer
echo gettype($a_bool); // prints out: boolean
echo gettype($a_str); // prints out: string
// If this is an integer, increment it by four
if (is_int($an_int)) {
$an_int += 4;
}
// If $bool is a string, print it out
// (does not print out anything)
if (is_string($a_bool)) {
echo "String: $a_bool";
}
?>
(1)Boolean 布尔类型
原文:http://my.oschina.net/lpe234/blog/322930