Can I use php to check whether a php file's syntax is iegal or not

13 views
Skip to first unread message

Reeze

unread,
Oct 6, 2009, 3:02:35 AM10/6/09
to Professional PHP Developers
Hi, All!

I wrote a simple template engine, it compile my template to php
file like Smarty does, but sometimes, the compiled php file syntax is
illegal, so how can I catch this "exception" in PHP.

Thanks

Best Regards
reeze.

crim...@googlemail.com

unread,
Oct 6, 2009, 7:37:30 PM10/6/09
to Professional PHP Developers


On 6 окт, 10:02, Reeze <reeze....@gmail.com> wrote:
> Hi, All!
>
>    I wrote a simple template engine, it compile my template to php
> file like Smarty does, but sometimes, the compiled php file syntax is
> illegal, so  how can I catch this "exception" in PHP.

http://www.php.net/manual/en/function.php-check-syntax.php

Gary Every

unread,
Oct 6, 2009, 9:24:01 PM10/6/09
to professi...@googlegroups.com
$filename = '/tmp/phpfile.php';
$output = exec('/usr/bin/php -l $filename');
if($output != 'syntax OK') {
 // you have an error, deal accordingly
}



--
Gary Every
"Pay it Forward!"

Reply all
Reply to author
Forward
0 new messages