note 20859 modified in function.eval by jsheets
| From: | jsheets@php.net | Date: | Sun, 09 Feb 2003 17:10:58 +0000 |
| Subject: | note 20859 modified in function.eval by jsheets | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-43697@lists.php.net to get a copy of this message | ||
Heres a little piece we used to parse apart HTML and eval the php embeded.
Eval doesn't seem to like any other "Stuff" in there..
function evalHTML ( $string ) {
$pos = 0;
/* Loop through to find the php code in html... */
while ( ($pos = strpos( $string, '<?' )) != FALSE ) {
/* Find the end of the php code.. */
$pos2 = strpos( $string, '?>', $pos + 2);
/* FIX: Eval outputs directly to the buffer. Catch / Clean it */
ob_start();
eval( substr( $string, $pos + 2, $pos2 - $pos - 2) );
$value = ob_get_contents();
ob_end_clean();
/* Grab that chunk! */
$string = substr( $string, 0, $pos ) . $value . substr( $string, $pos2 + 2);
}
return $string;
}
TODO: You might want to add error handling into this idea..
--was--
FIX ADDED! Please Ignore Prior Listing!
Heres a little piece we used to parse apart HTML and eval the php embeded.
Eval doesn't seem to like any other "Stuff" in there..
function evalHTML ( $string ) {
$pos = 0;
/* Loop through to find the php code in html... */
while ( ($pos = strpos( $string, '<?' )) != FALSE ) {
/* Find the end of the php code.. */
$pos2 = strpos( $string, '?>', $pos + 2);
/* FIX: Eval outputs directly to the buffer. Catch / Clean it */
ob_start();
eval( substr( $string, $pos + 2, $pos2 - $pos - 2) );
$value = ob_get_contents();
ob_end_clean();
/* Grab that chunk! */
$string = substr( $string, 0, $pos ) . $value . substr( $string, $pos2 + 2);
}
return $string;
}
TODO: You might want to add error handling into this idea..
http://www.php.net/manual/en/function.eval.php