Created
February 28, 2013 17:37
-
-
Save deekayen/5058566 to your computer and use it in GitHub Desktop.
Count all the lines of programming vs comments in a file after all the files within a directory have been concatenated together.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// find . -type f -exec cat {} > ../results.txt \; | |
$data = file_get_contents('/Users/davidnorman/Sites/lowescat.txt'); | |
$original = count(explode("\n", $data)); | |
print "Original lines: ". $original; | |
print "<br />\n"; | |
$data = preg_replace("/(\\/\\/.*\\n)/", "", $data); // remove single line comments, like this, from // to \\n | |
$data = preg_replace("/(\\/\\*.*\\*\\/)/", "", $data); // remove multi-line comments /* */ | |
$data = preg_replace("/(<![^>]*>)/", "", $data); // remove multi-line comments <!-- --> | |
//$fp = fopen('/Users/davidnorman/Sites/lowescat_stripped.txt', 'w'); | |
//fwrite($fp, $stripped); | |
//fclose($fp); | |
$filtered = count(explode("\n", $data)); | |
print "Comment-filtered lines: ". $filtered; | |
print "<br />\n"; | |
$math = (($original - $filtered) / $original) * 100; | |
print "Percent comments: $math%"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment