seval

seval
SYNOPSIS

seval($s)

DESCRIPTION

seval returns the result of the evaluation by PHP of $s.

CODE
  1. function seval($s) {
  2.     global $base_path, $base_url, $base_root;
  3.  
  4.     ob_start();
  5.     echo eval('?>'. $s);
  6.     return ob_get_clean();
  7. }

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

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

===

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].