2010-07-13 65 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