在ftp .txt php计算行数

时间:2014-12-24 11:14:03

标签: php count

我有一个问题:如何通过ftp计算文件中的行数?

赞:我有一个由ftp共享的C#生成的文件。如何在我的网络服务器上计算php的行数?

谢谢,Jonathan

1 个答案:

答案 0 :(得分:0)

如果您可以访问该文件,则可以执行此操作:

$file="yourfile.txt";
$count = 0;
$fp = fopen($file, "r");
while(!feof($fp)){
  $line = fgets($fp);
  $count++;
}

fclose($fp);

echo $count;

你也可以使用 count()

$count = count( file( $file));

但如果文件很大,你应该避免使用它。