php大小写问题
php5 版本中 变量区分大小写 常量默认区分大小写(false)
预定义变量和魔术常量必须是大写(区分大小写)
函数和对象不区分大小写(包括系统函数也不区分大小写)
而系统中使用的关键字也不区分大小写,比如if,else,for
对象的成员属性(相当于变量)区分大小写,对象的成员方法(相当于函数)不区分大小写
php6 版本中 全面区分大小写
删除Magic Quotes
php版本中兼容:
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
windows操作系统文件名不区分大小写
linux操作系统文件名区分大小写
为了网站开发兼容性和可移植新文件名建议区分大小写
如果网页文件中有php代码,文件后缀名必须为.php,不能为.html,否则服务器不能识别php代码;
除非修改Apache配置文件:AddType application/x-httpd-php .php .html
语句结束符:分号(;)
一条语句使用一个分号结束;
在一个php标记符范围内的最后一个分号可省略
php有结束标记省略则不能省略最后一个分号
php的注释
单行注释:
//注释内容
#注释内容
多行注释:
/*注释内容*/
PHP中的注释属于服务器端注释, 在PHP引擎解析注释时, 会自动忽略注释信息, 所以其并不会输出到客户端浏览器。
我们把这种注释就称之为"服务器端注释"。
函数和方法注释规范格式
/*
* 独立模式根据Identifier生成UserSig的方法
* @param int $identifier 用户账号
* @param int $expiry_after 过期时间
* @param multiple $value 值
* @param string $protected_key_path 私钥的存储路径及文件名
* @return string $out 返回的签名字符串
*/
文件头注释规范格式
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 许涛 < 449134904@qq.com>
// +----------------------------------------------------------------------
PHP 全称 Hypertext Preprocessor Language 超文本预处理语言
get_magic_quotes_gpc取得 PHP环境变量magic_quotes_gpc 的值。
语法: long get_magic_quotes_gpc(void);
返回值: 长整数函数种类: PHP 系统功能内容说明本函数取得 PHP 环境配置的变量magic_quotes_gpc (GPC, Get/Post/Cookie) 值。
返回 0 表示关闭本功能;
返回 1 表示本功能打开。
PHP 5.3.0 起废弃并将自 PHP 5.4.0 起移除。
当 magic_quotes_gpc 打开时,所有的 '(单引号), "(双引号), \(反斜线)和空字符会自动转为含有反斜线的转义字符。
实例
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") {
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}