note 23056 deleted from function.eval by danbrown

From: Date: Sun, 17 May 2009 20:01:52 +0000
Subject: note 23056 deleted from function.eval by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155312@lists.php.net to get a copy of this message
Note Submitter: olivier at revenu dot nom dot fr ---- Here an improved function of evalHTML discussed above (see brandon@louish.net or nathan vonnahme). I do some bench with a multi-line string contain php code <?echo "hello" ?> : for 1200 eval/replace => proceed 10 times faster for 12 eval/replace => proceed 3 times faster function also support both <? ?> and <?php ?> style... enjoy ! <?php function eval_buffer($string) { ob_start(); eval("$string[2];"); $ret = ob_get_contents(); ob_end_clean(); return $ret; } function eval_html($string) { return preg_replace_callback("/(<\?php|<\?)(.*?)\?>/si", "eval_buffer",$string); } ?> for older php version (< 4.0.5), it also possible to do it with preg_replace but it's a little slower (20 %) : <?php function eval_buffer($string) { ob_start(); eval(stripslashes("$string;")); $string = ob_get_contents(); ob_end_clean(); return $string; } function eval_html($string) { return preg_replace("/(<\?php|<\?)(.*?)\?>/sie", "eval_buffer('\\2')",$string); } ?>

« previous php.notes (#155312) next »