note 20634 deleted from function.preg-replace by sniper

From: Date: Sun, 07 Sep 2003 22:08:37 +0000
Subject: note 20634 deleted from function.preg-replace by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-55714@lists.php.net to get a copy of this message
Note Submitter: maxim@PHPBeginner.com ---- How to parse. I have just developed a little code parser for PHPBeginner.com. Here's how it works: You enclose any code of your text with the parenthesis like this: {code=php} .... {/code} You can even escape what you don't need by adding a backslash to it: {code=php} ... \{code} or /{code=php} ... {code} you can spesicy more than just PHP, whatever you wish and allow. So, here's the expression and supporting functions: function replace_php($str='') { Return "PHP ::: $str"; } function replace_html($str='') { Return "HTML ::: $str"; } $out = preg_replace( "/(([^\\\])\{code=(php|html)}(.*)(([^\\\])\{\/?code}))/ie", "'$2['.replace_$3('$4$6').']'", $text); This will take all of the PHP or HTML code you specify and will replace it (or do whatever else you wish) inside those functions. For more, you can simply add a new function and a new code tag. One only thing: make sure there are some characters within the code. Or, use (?!\\\) Cheers, Maxim Maletsky PHPBeginner.com

« previous php.notes (#55714) next »