19
seval
seval
SYNOPSIS
seval($s)
DESCRIPTION
seval returns the result of the evaluation by PHP of $s.
CODE
- function seval($s) {
- global $base_path, $base_url, $base_root;
- ob_start();
- echo eval('?>'. $s);
- return ob_get_clean();
- }
Adding the closing tag ?> at the beginning of the text protects from a tag <?php left opened in $s and garantees that all the code between the tags <?php and ?> contained in $s will be evaluated.
Declaring the global variables $base_path, $base_url and $base_root places them automatically in the context of the code which is being evaluated.
EXAMPLE
$ php -a
php> require_once 'library/seval.php';
php> $text='<p>1 + 1 = <?php echo 1+1; ?></p>';
php> echo seval($text);
<p>1 + 1 = 2</p>
php> quit
Comments