这个类可以列出文件的详细内容,统计一个目录下总代码行,你可以根据你的需要修改被统计的文件类型。 还可以限制统计类型 var$ext=array(php,phtml,php3,inc,js,html,htm,css,doc); 代码珠玑:http://www.codepearl.com/files/198.html php 源码与演示: 源码
这个类可以列出文件的详细内容,统计一个目录下总代码行,你可以根据你的需要修改被统计的文件类型。
还可以限制统计类型
var $ext = array(php,phtml,php3,inc,js,html,htm,css,doc);
代码珠玑:http://www.codepearl.com/files/198.html php 源码与演示:源码出处 演示出处
source code countdir=../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, filesize($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; } } else { return false; } } function summary($output=1) { // $output // 1 to generate a summary and file list // 0 to get an associative array with the totals if (!(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;$icnt);$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\n; print \n; print \n; print 简述: .$totalfolders.文件夹, .$totalfiles.文件, .$totallines. 行代码 \n; print
\n; print
\n; print \n; print \n; print 文件名/目录 \n; print 代码行数 \n; print
\n; print $listoutput; print
\n; print \n; print \n; print 简述: .$totalfolders.文件夹, .$totalfiles.文件, .$totallines.行代码 \n; print
\n; print
\n; print \n; } else { return array(files=>$totalfiles,lines=>$totallines,folders=>$totalfolders); } } }?>
