Ok, one more fix, this one includes checks to see how much code is between <?php and ?> tags... again there's probably a better or more accurate way, but this at least gives a rough idea. Used it because the project I'm doing includes alot of HTML outside the tags and I don't have time yet to get it separated like I'd like to. It also totals everything up at the end. Here it is: [code] <?php // Code Counter $comment_lines = 0; $code_lines = 0; $other_lines = 0; $total_lines = 0; $in_comment = false; foreach (glob("*.php") as $filename) { $thefile = file($filename); foreach($thefile as $key => $val){ if (trim($val) != '') { if (preg_match('/\<\?php/', trim($val))) { $in_php = true; } if ($in_php) { if ($in_comment) { if (trim($val) != "*/") { $comment_lines++; }else{ $comment_lines++; $in_comment = false; } }else{ if (substr(trim($val),0,2) == "//") { $comment_lines++; }else if (substr(trim($val),0,2) == "/*") { $comment_lines++; if (substr(trim($val), -2) != "*/") { $in_comment = true; } }else{ $code_lines++; } } }else{ $other_lines++; } if (preg_match('/\?\>/', trim($val))) { $in_php = false; } } } } echo "Lines of PHP code: $code_lines\n"; echo "Lines of other code: $other_lines\n"; echo "Lines of comments: $comment_lines\n"; $total_lines = $code_lines + $other_lines; echo "---------------------------------------------\n"; echo "Total Lines of code: $total_lines\n"; $total_lines += $comment_lines; echo "Total Lines(including comments): $total_lines\n"; ?> [/code]