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

Number of lines of code in php statistics file

王林
Release: 2023-04-07 21:38:01
Original
3098 people have browsed it

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;
 }
Copy after login

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 of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template