4images Forum & Community

General / Allgemeines => Programming => Topic started by: qBass17 on September 11, 2010, 02:07:40 AM

Title: preg_replace Problem
Post by: qBass17 on September 11, 2010, 02:07:40 AM
Did I done a different code found!

Hi,

the building for me is:
...
    $search_array = array(
      "/(\[)(list)(=)(['\"]?)([^\"']*)(\\4])(.*)(\[\/list)(((=)(\\4)([^\"']*)(\\4]))|(\]))/siU",
      "/(\[)(list)(])(.*)(\[\/list\])/siU",
      "/(\[\*\])/siU",
      "/(\[\/\*\])/siU",
      "/(\[)(url)(=)(['\"]?)(www\.)([^\"']*)(\\4])(.*)(\[\/url\])/siU",
      "/(\[)(url)(=)(['\"]?)([^\"']*)(\\4])(.*)(\[\/url\])/siU",
      "/(\[)(url)(])(www\.)([^\"]*)(\[\/url\])/siU",
      "/(\[)(url)(])([^\"]*)(\[\/url\])/siU",
      "/(\[)(code)(])(\r\n)*(.*)(\[\/code\])/siU",
      "/javascript:/si",
      "/about:/si",
      "/:D/si",
      "/(\:)\)/si",
      "/:(/si",
    );
    $replace_array = array(
      "<ol type=\"\\5\">\\7</ol>",
      "<ul>\\4</ul>",
      "<li>",
      "</li>",
      "<a href=\"http://www.\\6\" target=\"_blank\" rel=\"nofollow\">\\8</a>",
      "<a href=\"\\5\" target=\"_blank\" rel=\"nofollow\">\\7</a>",
      "<a href=\"http://www.\\5\" target=\"_blank\" rel=\"nofollow\">www.\\5</a>",
      "<a href=\"\\4\" target=\"_blank\" rel=\"nofollow\">\\4</a>",
      "<pre>Code:<hr size=1>\\5<hr size=1></pre>",
      "java script:",
      "about :",
      "<img src=\"./board/wcf/images/smilies/biggrin.png\" alt=\":D\">",
      "<img src=\"./board/wcf/images/smilies/smile.png\" alt=\":)\">",
      "<img src=\"./board/wcf/images/smilies/sad.png\" alt=\":)\">"
    );
    $text = preg_replace($search_array, $replace_array, $text);
    if (!$bbcode_img)  {
      $text = preg_replace("/(\[)(img)(])(\r\n)*([^\"]*)(\[\/img\])/siU", "<a href=\"\\5\" target=\"_blank\">\\5</a>", $text);
    }
    else  {
      $text = preg_replace("/(\[)(img)(])(\r\n)*([^\"]*)(\[\/img\])/siU", "<img src=\"\\5\">", $text);
    }
    $text = preg_replace("/(\[)(b)(])(\r\n)*([^\"]*)(\[\/b\])/siU", "<b>\\5</b>", $text);
.....

It's about this smiley ""/:(/si"," and "/(\8)\)/si",
I do not get converted, I have tried all variations ... someone knows more?
Title: Re: preg_replace Problem
Post by: V@no on September 11, 2010, 04:47:32 AM
You must escape parenthesis:
Code: [Select]
      "/:\)/si",
      "/:\(/si",