错误日志
- 根据在php.ini中的error_log配置,php向服务器的错误记录系统或文件发送错误记录。
- 通过使用error_log()函数,我们可以向指定的文件或远程目的地发送错误记录。
//信息,类型(0是覆盖,3是追加),目的地(保存路径),额外信息
bool error_log(string $message[,int $message_type=0[,string $destination[,string $extra_headers]]])
简单案例
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
</head>
<body>
<?php
function myError($errorNo,$errorMessage){
$message=$errorNo." ".$errorMessage;
echo $message;
//文件的回车换行\r\n
//页面的回车换行<br/>
//0覆盖,3追加
error_log($message."\r\n",3,"error.txt");
}
//常用错误级别:E_USER_WARNING,E_USER_NOTICE,E_USER_ERROR
set_error_handler("myError",E_USER_WARNING);
$age=300;
if($age>150){
//触发错误
trigger_error("输入年龄过大",E_USER_WARNING);
}
?>
</body>
</html>

时间函数
- time():到当前时间的秒数。
- date_default_timezone_set(“不同国家有不同的时区”);
- date(“时间格式”,time());
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
</head>
<body>
<?php
echo time()."<br/>";
//默认时区是UTC,中国是PRC
date_default_timezone_set("PRC");
//time()默认,可写可不写
echo date("Y-m-d G-i-s",time());
?>
</body>
</html>
