php+代码行数常量,php统计文件中的代码行数
生活随笔
收集整理的這篇文章主要介紹了
php+代码行数常量,php统计文件中的代码行数
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
函數介紹:
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+代码行数常量,php统计文件中的代码行数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 计算机存储技术及应用,计算机数据安全存储
- 下一篇: java java.doc_使用 jav