View sourcecode
Choose file:
Start counting:
"; if (isset($_POST['uploaden'])) { echo "

Total amount of semicolons counted: ".count_semicolons_file(0, $_FILES['semi_upload']['tmp_name'])."
"; echo "

semicolons not in comments: ".count_semicolons_file(1, $_FILES['semi_upload']['tmp_name'])."
"; } function count_semicolons_file ($checkmode, $filepath) { $fileToOpen = fopen($filepath,"r"); $fileread = fread($fileToOpen, filesize($filepath)); fclose($fileToOpen); $filearray = explode("\n", $fileread); switch ($checkmode) { case 0: return substr_count($fileread, ";"); break; case 1: $scb = 0; //$searchcommentblock variable $count = 0; for ($num = 0; $num < sizeof ($filearray); $num ++) { //search comment blocks if ($scb == 0) { $start = strpos($filearray[$num], "/*"); if ($start === false) {$start = strlen($filearray[$num]); $result = $filearray[$num];} else {$scb = 1;} } if ($scb == 0) { //remove normal comments $start = strpos($filearray[$num], "//"); if ($start === false) {$start = strlen($filearray[$num]); $result = $filearray[$num];} else {$result = substr_replace($filearray[$num], "", $start);} } //remove comment block lines if ($scb == 1) { $start = strpos($filearray[$num], "*/"); if ($start === false) {$start = strlen($filearray[$num]); $result = substr_replace($filearray[$num], "", 0);} else {$scb = 0; $result = substr($filearray[$num], $start+2);} } $counter += substr_count($result, ";"); } return $counter; break; } } ?>