php中'\r \t \n'占用多少字节

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 行.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

SHUIPING_YANG

你的鼓励是我创作的最大动力。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值