note 82448 deleted from function.php-check-syntax by thiago
| From: | thiago@php.net | Date: | Fri, 12 Dec 2008 11:43:37 +0000 |
| Subject: | note 82448 deleted from function.php-check-syntax by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-148069@lists.php.net to get a copy of this message | ||
Note Submitter: alx at inbox dot lv
----
Nope guys.. to check the valid php you must do the followed:
<?
function checkPHP($source) {
ob_start();
$sowhat = @eval('?>'.$source);
$GLOBALS['sowhat'] = ob_get_contents();
ob_end_clean();
return $sowhat === NULL ? true : false;
}
$source = '
bla bla <?=$foo?> some stuff <?
foreach ($somethins as $somethig) {
// whatever
}';
if (checkPHP($source)) {
echo 'PHP code is correct';
} else {
echo 'there are errors in your php: '.$GLOBALS['sowhat'];
}