note 85836 added to function.preg-replace-callback

From: Date: Fri, 19 Sep 2008 19:59:10 +0000
Subject: note 85836 added to function.preg-replace-callback
Groups: php.notes 
Request: Send a blank email to php-notes+get-144558@lists.php.net to get a copy of this message
The last example -nested BBCode- has a problem and won't work it should be <?php $regex = '#\[indent]((?:[^\[]|\[(?!/?indent])|(?R))+)\[/indent]#'; ?> ([ should be escaped to be \[) -- a nicer regex i used in a BBCode parser (BBEngine http://www.phpclasses.org/browse/package/4829.html) This one Captures Tag Arguments ,Empty tags and also uses ?> for performance , wrapped in a simple function for templating (ofcourse it's one line but note's line size is limited :) ) <?php /** * A Template for the recursive tags matcher RE * it generates it for a given tag ,open bracket and closing one * $O & $C must be pre-escaped from #'s * @param String $tag Tag to be parsed recursively * @param String $O Opeening brackets of tag * @param String $C Closing brackets of tag */ public function Recursive_RE_Generator($tag,$O,$C) { $re="#{$O}({$tag}.*?){$C}((?>{$O}(?!/?{$tag}[^{$O}]*?{$C})| [^{$O}]|(?R))*){$O}/{$tag}{$C}#is"; return $re; } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 84.36.248.70 ---- Manual Page -- http://www.php.net/manual/en/function.preg-replace-callback.php Edit -- https://master.php.net/note/edit/85836 Del: integrated -- https://master.php.net/note/delete/85836/integrated Del: useless -- https://master.php.net/note/delete/85836/useless Del: bad code -- https://master.php.net/note/delete/85836/bad+code Del: spam -- https://master.php.net/note/delete/85836/spam Del: non-english -- https://master.php.net/note/delete/85836/non-english Del: in docs -- https://master.php.net/note/delete/85836/in+docs Del: other reasons-- https://master.php.net/note/delete/85836 Reject -- https://master.php.net/note/reject/85836 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#144558) next »