Home >Backend Development >PHP Tutorial >Number of lines of code in php statistics file

Number of lines of code in php statistics file

王林
王林Original
2019-12-03 09:53:073058browse

Number of lines of code in php statistics file

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn