类别:PHP教程 / 日期:2019-12-03 / 浏览:220 / 评论:0

函数引见:

file_get_contents() 把全部文件读入一个字符串中。

explode() 函数运用一个字符串支解另一个字符串,并返回由字符串构成的数组。

count() 函数返回数组中元素的数量。

在线视频教程分享:php视频教程

示例以下:

public function totalByFile($fullFileName) {
 $fileContent = file_get_contents($fullFileName);
 $lines = explode("\n", $fileContent);
 $lineCount = count($lines);
  
 for($i = $lineCount -1; $i > 0; $i -= 1) {
  $line = $lines[$i];
  if ($line != "") break;
  $lineCount -= 1; //末了几行是空行的要去掉。
 }
 unset($fileContent);
 unset($lines);
  
 $totalCodeInfo = new TotalCodeInfo();
 $totalCodeInfo->setFileCount(1);
 $totalCodeInfo->setLineCount($lineCount);
 return $totalCodeInfo;
 }

相干文章教程引荐:php入门教程

以上就是php统计文件中的代码行数的细致内容,更多请关注ki4网别的相干文章!

打赏

感谢您的赞助~

打开支付宝扫一扫,即可进行扫码打赏哦~

版权声明 : 本文未使用任何知识共享协议授权,您可以任何形式自由转载或使用。

 可能感兴趣的文章