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;
}
~or@instead of/."@[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]@is",pattern even [img] ... [/img] is matching with it just comment them and try again you will see it will be repleaced in well form or put this pattern line to the end of the arraypreg_quoteinstead of escaping every single block of code.<div align=\"center\" style=\"text-align:center; width:50%;\">$1</div>as replacement string, use for example<div class="center">$1</div>and define the CSS class.center(try to find an other name:) in a separate file. Two advantages of doing this: 1) your html code will be shorter. 2) the day you want to change how messages look like, you only need to edit the css classes.