我试图让bbcode图像工作。但我有问题。
代码中的错误是什么?为什么?
我有这个输入:
[img]http://www.joomlaworks.net/images/demos/galleries/abstract/7.jpg[/img]
并希望如此:
<img src="http://www.joomlaworks.net/images/demos/galleries/abstract/7.jpg">
但结果是:
`问:我怎样才能使这项工作正常进行?
完整代码:
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;
}
答案 0 :(得分:1)
问题在于你的
"@[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]@is"
模式,甚至[img] ... [/ img]只是匹配它,评论它们并再试一次,它将以井身形式重新填充或将此模式线放到数组的末尾