如果他希望用图像表情替换笑脸,我想给用户一个机会。
我试过了。
bbcode($text, TRUE);
function bbcode($str, $smileys = false)
{
$str = htmlentities($str);
$find = array(
if ($smileys == true) {
':p',
}
'/\[b](.*?)\[\/b]/i',
'/\[u](.*?)\[\/u]/i',
'/\[i](.*?)\[\/i]/i',
'/\[img](.*?)\[\/img]/i',
'/\[url](.*?)\[\/url]/i',
'/\[color=(.*?)\](.*?)\[\/color]/i',
'/\[size=(.*?)\](.*?)\[\/size]/i'
);
$replace = array(
if ($smileys == true) {
'<img src="/img/toungue.gif">',
}
'<strong>$1</strong>',
'<u>$1</u>',
'<i>$1</i>',
'<img src="$1" alt="$1" />',
'<a href="$1" target="_blank" rel="nofollow" title="$1">$1</a>',
'<span style="color:$1">$2</span>',
'<span style="font-size:$1">$2</span>'
);
$str = preg_replace($find, $replace, $str);
return nl2br($str);
}
我猜你不能在数组中使用if子句。
我也尝试过:
function bbcode($str, $smileys = false)
{
$str = htmlentities($str);
$find = array(
'/\[b](.*?)\[\/b]/i',
'/\[u](.*?)\[\/u]/i',
'/\[i](.*?)\[\/i]/i',
'/\[img](.*?)\[\/img]/i',
'/\[url](.*?)\[\/url]/i',
'/\[color=(.*?)\](.*?)\[\/color]/i',
'/\[size=(.*?)\](.*?)\[\/size]/i'
);
$replace = array(
'<strong>$1</strong>',
'<u>$1</u>',
'<i>$1</i>',
'<img src="$1" alt="$1" />',
'<a href="$1" target="_blank" rel="nofollow" title="$1">$1</a>',
'<span style="color:$1">$2</span>',
'<span style="font-size:$1">$2</span>'
);
if ($smileys == true) {
$find = array(
':p'
);
$replace = array(
'<img src="/img/toungue.gif">'
);
}
$str = preg_replace($find, $replace, $str);
return nl2br($str);
}
等于=无结束分隔符':'在第68行的functions.php中找到