This class lists the details of a file and counts the total code lines in a directory. You can modify the file type to be counted based on your needs. You can also limit the statistical type var $ extarray (php, phtml, php3, inc, js, html, htm, css, doc); Code: www.codepearl.comfiles198.html PHP source code and demo: source code
This class lists the details of a file and counts the total code lines in a directory. You can modify the file type to be counted based on your needs. You can also limit the statistical type var $ ext = array (php, phtml, php3, inc, js, html, htm, css, doc); Code pearl: http://www.codepearl.com/files/198.html PHP source code and demo: source code
This class lists the details of a file and counts the total code lines in a directory. You can modify the file type to be counted based on your needs.
You can also limit the statistical type.
Var $ ext = array ("php", "phtml", "php3", "inc", "js", "html", "htm", "css ", "doc ");
Code pearl: http://www.codepearl.com/files/198.html PHP
Source code and demo:Source code source demonstration Source
Source Code Count
dir="../linecount";// Use this method to output the summary and list of files to the page// You can customize the HTML from within the class$lineCount->summary(1);// Use this method to get the totals as an associative array:$totals = $lineCount->summary(0);# echo $totals["folders"] / $totals["files"] / $totals["lines"]?>
CountLines ($ filePath);} else {// Item is a file, get some info about it $ fileName = explode ("/", $ filePath ); $ fileDir = $ fileName [(count ($ fileName)-2)]; $ fileName = $ fileName [(count ($ fileName)-1)]; $ fileExt = explode (". ", $ fileName); $ fileExt = $ fileExt [(count ($ fileExt)-1)]; if (in_array ($ fileExt, $ this-> ext )) {// Open the file, get line count $ fp = fopen ($ filePath, "r"); $ buffer = rawurlencode (fread ($ fp, fil Esize ($ filePath); $ buffer = explode ("% 0A", $ buffer); $ numLines = count ($ buffer); fclose ($ fp ); // Add the information to our count array $ this-> cnt [$ this-> x] ['dir'] = $ dir; $ this-> cnt [$ this-> x] ['file'] = $ fileName; $ this-> cnt [$ this-> x] ['Count'] = $ numLines; $ this-> x ++ ;}}} closedir ($ handle );} else {return false ;}} function summary ($ output = 1) {// $ output // 1 to generate a summary and File list // 0 to get an associative array with the totalsif (! (Is_dir ($ this-> dir) {// No directory given, use document root $ this-> dir = $ _ SERVER ['document _ root'];} $ this-> countLines ($ this-> dir); $ listOutput = ""; $ totalLines = 0; $ usedDir = array (); for ($ I = 0; $ I
Cnt); $ I ++) {$ totalLines + = $ this-> cnt [$ I] ['Count']; if (! (In_array ($ this-> cnt [$ I] ['dir'], $ usedDir) {if ($ output = 1) {$ listOutput. ="\ N "; $ listOutput. ="
". Iconv (" GB2312 "," UTF-8 ", $ this-> cnt [$ I] ['dir'])."\ N "; $ listOutput. ="\ N ";}$ usedDir [] = $ this-> cnt [$ I] ['dir'];} if ($ output = 1) {$ listOutput. ="\ N "; $ listOutput. ="". Iconv (" GB2312 "," UTF-8 ", $ this-> cnt [$ I] ['file'])."\ N "; $ listOutput. ="". Number_format ($ this-> cnt [$ I] ['Count'])."\ N "; $ listOutput. ="\ N ";}}$ totalFiles = number_format (count ($ this-> cnt); $ totalLines = number_format ($ totalLines ); $ totalFolders = number_format (count ($ usedDir); if ($ output = 1) {print"
\ N "; print"
". $ This-> dir ."
\ N "; print"
\ N "; print"
\ N "; print"
Brief description:". $ TotalFolders." folder, ". $ totalFiles." file, ". $ totalLines." line code | \ N "; print"
\ N "; print"
\ N "; print"
\ N "; print"
\ N "; print"
File Name/directory | \ N "; print"
Number of lines of code | \ N "; print"
\ N "; print $ listOutput; print"
\ N "; print"
\ N "; print"
\ N "; print"
Brief description:". $ TotalFolders." folder, ". $ totalFiles." file, ". $ totalLines." line code | \ N "; print"
\ N "; print"
\ N "; print"
\ N ";}else {return array (" files "=>$ totalFiles," lines "=>$ totalLines," folders "=>$ totalFolders) ;}}}?>