note 21604 added to function.eval
| From: | nathan@php.net | Date: | Tue, 21 May 2002 00:28:50 +0000 |
| Subject: | note 21604 added to function.eval | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-30820@lists.php.net to get a copy of this message | ||
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;
}
--
http://www.php.net/manual/en/function.eval.php
http://master.php.net/manage/user-notes.php?action=edit+21604
http://master.php.net/manage/user-notes.php?action=delete+21604
http://master.php.net/manage/user-notes.php?action=reject+21604