Function introduction:
file_get_contents()
Read the entire file into a string.
explode()
The function uses one string to split another string and returns an array composed of strings.
count()
The function returns the number of elements in the array.
Online video tutorial sharing: php video tutorial
Examples are as follows:
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; }
Related article tutorial recommendations:php introductory tutorial
The above is the detailed content of Number of lines of code in php statistics file. For more information, please follow other related articles on the PHP Chinese website!