php之stream_get_line函数和fget函数读取文件
1.txt内容如下
1111111111111111111112111111111111111111111211111111111111233333333333333
stream_get_line示例
<?php
 $file_path = './1.txt';
 $fp = fopen($file_path, 'r') or die("open file failure!");
 $line = 0;
 if ($fp) {
     while ($info = stream_get_line($fp, 8192, "2")) {  //以2为分隔符
         $line++;
     }
     fclose($fp); 
 }
 echo $line; //结果是4fgets示例
<?php
 $file_path = './1.txt';
 $fp = fopen($file_path, 'r') or die("open file failure!");
 $line = 0;
 if ($fp) {
     while ($info = fgets($fp, 8192)) {
         $line++;
     }
     fclose($fp); 
 }
 echo $line; //结果是1总结
stream_get_line()函数与fgets()几乎相同,只是它允许除标准、标准和\r\n之外的行尾分隔符,并且不返回分隔符本身。

已有 0 条评论