http://php.net/preg_replace_all And be sure to use Ungreedy flag to your pattern: /pattern/U On Sat, April 14, 2007 11:22 pm, Travis Moore wrote: > Okay, so what I have is a BB code type of thing for a CMS, which I for > obvious reasons can't allow HTML. > > Here's the snippet of my function: > > ******** > function bbCode($str) > { > $db = new _Mysql; > $strOld = $str; > $strNew = $str; > $getRegexs = $db->query("SELECT `regex`,`replace`,`search` FROM > `_bb_codes`"); > while ($getRegex = mysql_fetch_assoc($getRegexs)) > { > $search = base64_decode($getRegex['search']); > $regex = base64_decode($getRegex['regex']); > $replace = base64_decode($getRegex['replace']); > if (preg_match($search,$strNew) == 1) > { > for ($i = 1; $i < 20; $i++) > { > $strNew = $strOld; > $strNew = preg_replace($regex,$replace,$strNew); > if ($strNew == $strOld) > { > break; > } > else > { > $strOld = $strNew; > } > } > } > } > $return = $strNew; > return $return; > } > ********** > > But, for something like this: > > [quote][quote]Quote #2[/quote]Quote #1[/quote]No quote. > > I'll get: > > <div class="quoteContainer"> > [quote]Quote #2[/quote]Quote #1</div> > No quote. > > Despite being in the loop. > > Regex is: /\[quote\]((.*|\n)*)\[\/quote\]/ > Replace is: <div class="messageQuote">$1</div> > > Both are stored base64 encoded in a database. > > Any help / suggestions much appreciated. > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php