Recursive PHP Syntax Checker





13
Date Submitted Fri. Oct. 20th, 2006 8:10 PM
Revision 1 of 1
Beginner stalfos
Tags PHP | Recursive | syntax
Comments 1 comments
Recursively checks for all *.php and *.tpl files in the directory specified (or the current directory if one is not specified) and runs `php -l $file`. Only outputs the errors.
<?php

$start_dir = (isset($argv[1])) ? $argv[1] : '.';

check_syntax($start_dir);

function check_syntax($path) {

        foreach(scandir($path) as $file) {

                if($file != '.' && $file != '..') {

                        if(is_dir("$path/$file")) {

                                check_syntax("$path/$file");

                        } else if(preg_match("/.\.(php|tpl)$/", $file)) {

                                $result = `php -l $path/$file`;
                                if($result[0] != 'N') echo $result;
                        }
                }
        }
}

?>

Michael Cooney

Comments

Comments Amazing
Fri. Oct. 20th, 2006 8:14 PM    Newbie JeremyGiberson

Voting