note 20634 added to function.preg-replace

From: Date: Wed, 10 Apr 2002 20:36:37 +0000
Subject: note 20634 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-29083@lists.php.net to get a copy of this message
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 -- http://www.php.net/manual/en/function.preg-replace.php http://master.php.net/manage/user-notes.php?action=edit+20634 http://master.php.net/manage/user-notes.php?action=delete+20634 http://master.php.net/manage/user-notes.php?action=reject+20634

« previous php.notes (#29083) next »