The tool is written in PHP, requiring files under the file to be PHP files (that is, files ending in. php), you can count the amount of PHP code in a folder, the code is as follows:
<?php$filename = "d:/code/";//php code Directory $counts = 0;function Codecount ($filename) {global $counts; $total = 0; Total number of rows $space = 0; Number of empty rows $notes = 0; Note $handle = fopen ($filename, "R"); $isNotes = false; while (! feof ($handle)) {$line = Fgets ($handle); $total + +; if ($isNotes) {$notes + +; if (Preg_match ("/.* (\*\/)/", $line)) {//multi-line */comment end $isNotes = false; } continue; } if (Preg_match ("/^[\s]*$/", $line)) {//blank line $space + +; } elseif (Preg_match ("/^[\s]*\/\//", $line)) {//two bar comment $notes + +; } elseif (Preg_match ("/^[\s]* (\/\*). * (\*\/) [\s]*$/", $line)) {//single-line comment $notes + +; } elseif (Preg_match ("/^[\s]* (\/\*). * *", $line)) {//Multiline//* Comments start $notes + +; $isNotes = true; }} echo "Total:". $total. "\ r \ n"; echo "Space:". $space. "\ r \ n"; echo "notes:". $notes. "\ r \ n"; echo "<bR> "; $counts + = ($total-$space-$notes);} if (Is_file ($filename)) {codecount ($filename);} else if (Is_dir ($filename)) {if ($dh = Opendir ($filename)) {while ($file = Readdir ($DH))! = False) {//The full path of the file name contains the file name $filePath = $filena Me. $file; Gets the file modification time if (Is_file ($filePath)) {codecount ($filePath); }} closedir ($DH); }}echo "<br>". $counts;//Output Total code volume?>
PHP Code Statistics Tool