|
Posted by Dima Vidmich on 09/20/06 09:17
Recently I think about some sort of safe includes which will not fail
if parse error happened. And many different sourses said that this is
imposible without some non standard modules and without calling "perl
-l"
I made some investigation and found this way:
function check_syntax($filename)
{
// load file
$code = file_get_contents($file);
// remove non php blocks
$code = preg_replace('/(^|\?>).*?(<\?php|$)/i', '', $code);
// create lambda function
$f = @create_function('', $code);
// return function error status
return !empty($f);
}
This function will return true if code ok or false if not. Maybe it
will be usefull for somebody...
WBR,
Dima Vidmich
Navigation:
[Reply to this message]
|