I want to give the oppurtunity to the user if he wants his smileys to be replaced with image smileys.
I tried this.
bbcode($text, TRUE);
function bbcode($str, $smileys = false)
{
$str = htmlentities($str);
$find = array(
if ($smileys == true) {
':p',
}
'/\[b](.*?)\[\/开发者_JAVA百科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);
}
I guess u cant have if clause in array.
And i also tried:
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);
}
Equals to = No ending delimiter ':' found in functions.php on line 68
I guess u cant have if clause in array.
Yes you can, but it's called a ternary.
精彩评论