maria
maria

Reputation: 159

preg_replace php image messup

Im trying to get the bbcode image to work. But i have problems with it.

what in the code is wrong and why?

I have this input:

[img]http://www.joomlaworks.net/images/demos/galleries/abstract/7.jpg[/img]

and would like it to be:

<img src="http://www.joomlaworks.net/images/demos/galleries/abstract/7.jpg">

but the result is:

`Q: How can i make this work properly?

Full code:

 function parsebb($body,$userid = false, $user2 = false) {
            $find = array(
                "@\n@",
                "@[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]@is",
                "/\[url\=(.+?)\](.+?)\[\/url\]/is",
                "/\[b\](.+?)\[\/b\]/is",
                "/\[i\](.+?)\[\/i\]/is",
                "/\[u\](.+?)\[\/u\]/is",
                "/\[farge\=(.+?)\](.+?)\[\/farge\]/is",
                "/\[size\=(.+?)\](.+?)\[\/size\]/is",
                "/\[font\=(.+?)\](.+?)\[\/font\]/is",
                "/\[boks\=venstre\](.+?)\[\/boks\]/is",
                "/\[boks\=hoyre\](.+?)\[\/boks\]/is",
                "/\[boks\=midten\](.+?)\[\/boks\]/is",
                "/\[img\](.+?)\[\/img\]/is",
                "/\[email\](.+?)\[\/email\]/is",
                "/\[midten\](.+?)\[\/midten\]/is",
                "/\[venstre\](.+?)\[\/venstre\]/is",
                "/\[hoyre\](.+?)\[\/hoyre\]/is",
            );

            $replace = array(
                "<br />",
                "<a href=\"\\0\">\\0</a>",
                "<a href=\"$1\" target=\"_blank\">$2</a>",
                "<strong>$1</strong>",
                "<em>$1</em>",
                "<span style=\"text-decoration:underline;\">$1</span>",
                "<font color=\"$1\">$2</font>",
                "<font size=\"$1\">$2</font>",
                "<span style=\"font-family: $1\">$2</span>",
                "<div align=\"left\" style=\"text-align:center; width:50%; \">$1</div>",
                "<div align=\"right\" style=\"text-align:center; width:50%;\">$1</div>",
                "<div align=\"center\" style=\"text-align:center; width:50%;\">$1</div>",
                "<img src=\"$1\">",
                "<a href=\"mailto:$1\" target=\"_blank\">$1</a>",
                "<div style=\"text-align:center;\">$1</div>",
                "<div style=\"text-align:left;\">$1</div>",
                "<div style=\"text-align:right;\">$1</div>",


            );


                $body = htmlspecialchars($body);
                $body = preg_replace($specialCodes, $specialCodesReplace, $body);




            return $body;
        }

Upvotes: 1

Views: 65

Answers (1)

Santa&#39;s helper
Santa&#39;s helper

Reputation: 996

The problem is at your

"@[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]@is"

pattern, even [img] ... [/img] is matching with it just, comment them and try again, it will be repleaced in well form or put this pattern line to the end of the array

Upvotes: 1

Related Questions