Reply to check syntax before include

Your name:

Reply:


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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация