note 42760 deleted from function.preg-replace-callback by nlopess

From: Date: Wed, 30 Jun 2004 19:19:23 +0000
Subject: note 42760 deleted from function.preg-replace-callback by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-72185@lists.php.net to get a copy of this message
Note Submitter: aleksandar_markovic@netsector.net ---- This simple code evaluate PHP code stored in string (generally stored in some database back end). This code will look for <php> as starting tag and </php> as ending tag. In this tag can be any PHP code which result will replace the original code. Sample code: <?php $html_data = 'Some html...<br>'; $html_data .= 'some php output...<php>return 2+2;</php><br>'; $html_data .= 'some php include...<php>include ("file.php");</php>'; function myeval($input) { if (preg_match ("/include/i", $input[1])) { ob_start(); eval($input[1]); $buffer = ob_get_clean(); return $buffer; } else return eval($input[1]); } $tag_search = "/\<php>(.*?)\<\/php>/si"; $html_data = preg_replace_callback($tag_search,"myeval",$html_data); echo $html_data; ?> Output: Some html... some php output...4 some php include...[output of file.php]

« previous php.notes (#72185) next »