wamp中’\r \t \n’占用多少字节?
var_dump(“\r”);
D:\wamp64\www\test\test.php:39:string ' ' (length=1)
var_dump(“\t”);
D:\wamp64\www\test\test.php:39:string ' ' (length=1)
var_dump(“\n”);
D:\wamp64\www\test\test.php:39:string '
' (length=1)
是不是已经很明确了?都是占用一个字节!linux下面未测试。
这个实在操作文件指针的时候会用到,倒序输出文件最后的几行。代码如下:
function FileLastLines($filename,$n){
if(!$fp=fopen($filename,'r')){
echo "打开文件失败,请检查文件路径是否正确,路径和文件名不要包含中文";
return false;
}
$pos=-2;
$eof="";
$str="";
while($n>0){
while($eof!="\n"){
if(!fseek($fp,$pos,SEEK_END)){
$eof=fgetc($fp);
$pos--;
}else{
break;
}
}
$str.=fgets($fp);
$eof="";
$n--;
}
fclose($fp);
return $str;
}
调用:
echo nl2br(FileLastLines('php_error.log',10));
最近十条日志信息为:
[2017-02-17 11:03:16] Uncaught Error: Class 'ArticleModel' not found in /www/SHUIPING_YANG/controller/Article.controller.php:26 thrown /www/common.lib.dunhetech.com/framework/JetLite/JetMVC.class.php 第 156 行.
#1 {main}
#0 /www/SHUIPING_YANG/cli2cgi.php(123): JetMVC->execute()
Stack trace:
[2017-02-09 16:26:51] Uncaught Error: Class 'Map' not found in /www/common.lib.dunhetech.com/framework/JetLite/JetMVC.class.php:156
[2017-02-09 16:26:49] syntax error, unexpected end of file /www/SHUIPING_YANG/controller/Map.controller.php 第 308 行.
[2017-02-09 15:42:55] syntax error, unexpected end of file, expecting ')' /www/SHUIPING_YANG/config/Arr.config.php 第 1423 行.
[2017-02-09 15:42:53] syntax error, unexpected end of file, expecting ')' /www/SHUIPING_YANG/config/Arr.config.php 第 1423 行.
[2017-02-09 15:42:52] syntax error, unexpected end of file, expecting ')' /www/SHUIPING_YANG/config/Arr.config.php 第 1423 行.