日期:2014-05-17  浏览次数:20563 次

=====菜鸟提问:php 读取文本文件的问题=====
我写了一个通过php读取文本文件的函数,统计该文本的总行数,空行不计,但我不知道如何判断某行是否为空,每次都把空行统计进去了,请各位高人指点啊,我是初学php的,函数如下,$file   为指定文本文件路径
function   getFileCount($file){
$count=0;

$fd=   fopen($file,   "r ");
while(($line=fgets($fd,4096))!= " "){
        $count++;
}
fclose($fd);
return   $count;
}

------解决方案--------------------
trim($line) == ' '
------解决方案--------------------
trim($line) && $count++;
------解决方案--------------------
function getFileCount($file){
$count=0;
$lines = file($file);
foreach($lines as $line)
{
if(trim($line) != ' ') $count++;
}
return $count;
}

这个应该可以的.