2010-07-13 109 views
0

我想给用户提供oppurtunity,如果他希望他的表情用图像表情符号代替。PHP函数bbcode使可选来替换表情符号

我试过了。

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); 
} 

我猜ü不能有,如果子句中的数组。

,我也尝试过:

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); 
} 

等于=没有结束符“:”在functions.php的发现上线68

回答

1

我猜ü不能有,如果子句中的数组。

是的,你可以,但它叫做ternary