note 21604 deleted from function.eval by nlopess
| From: | nlopess@php.net | Date: | Tue, 18 May 2004 13:38:01 +0000 |
| Subject: | note 21604 deleted from function.eval by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-69765@lists.php.net to get a copy of this message | ||
Note Submitter: nathan vonnahme
----
yeah, wouldn't you know I'd post a buggy version. Here is a better one. It will work
through more than one php tag in the string, and won't chop off bits like the one I posted
previously. Still, it's not perfect. If you improve it I'd appreciate email at nathan at
enteuxis dddot org.
function evalHTML ( $string ) {
$pos = 0;
$start = 0;
/* Loop through to find the php code in html... */
while ( ($pos = strpos( $string, '<?php', $start )) != FALSE ) {
/* Find the end of the php code.. */
$pos2 = strpos( $string, "?>", $pos + 5);
/* Eval outputs directly to the buffer. Catch / Clean it */
ob_start();
eval( substr( $string, $pos + 5, $pos2 - $pos - 5) );
$value = ob_get_contents();
ob_end_clean();
/* Grab that chunk! */
$start = $pos + strlen($value);
$string = substr( $string, 0, $pos ) . $value . substr( $string,
$pos2 + 2);
}
return $string;
}