preg_replace and regular expressions.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux