note 21403 added to function.eval

From: Date: Sat, 11 May 2002 16:32:55 +0000
Subject: note 21403 added to function.eval
Groups: php.notes 
Request: Send a blank email to php-notes+get-30473@lists.php.net to get a copy of this message
The (very usefull) function to parse apart HTML and eval the php embeded, is not 100% fullproof. With a small modification (!== instead of !=) it is 100% fullproof: 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); echo "pos2= ".$pos2."<hr>\n"; /* 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; } -- http://www.php.net/manual/en/function.eval.php http://master.php.net/manage/user-notes.php?action=edit+21403 http://master.php.net/manage/user-notes.php?action=delete+21403 http://master.php.net/manage/user-notes.php?action=reject+21403

« previous php.notes (#30473) next »