Look, if forum post have $hide_smilies is set to 1, I dont want the :p, :o to be replacen with images.
This is how I output forum post bbcode($message);
And Function:
function bbcode($str)
{
$str = htmlentities($str);
$find = array(
"/:p/",
"/:o/",
'/\[b](.*?)\[\/b]/is',
'/\[u](.*?)\[\/u]/is',
'/\[i](.*?)\[\/i]/is'
);
$replace = array(
'<img src="/images/forum/icon_tongue.gif" alt=":p" border="0" height="15" width="15">',
'<img src="/images/forum/icon_embarrassed.gif" alt=":o" border="0" height="15" width="15">'
'<strong>$1</strong>',
'<u>$1</u>',
'<i>$1</i>',
$str = preg_replace($find, $replace, $str);
return nl2br($str);
Thanks
Edit
function bbcode($str, $hide_smilies = 0)
{
$str = htmlentities($str);
$find = array(
'/\[b](.*?)\[\/b]/is',
'/\[u](.*?)\[\/u]/is',
'/\[i](.*?)\[\/i]/is',
);
$replace = array(
'<strong>$1</strong>',
'<u>$1</u>',
'<i>$1</i>'
);
if ($hide_smilies == 0)
{
$find[] = "/:p/";
$find[] = "/:o/";
$replace[] = '<img src="/images/forum/icon_tongue.gif" alt=":p" border="0" height="15" width="15">';
$replace[] = '<img src="/images/forum/icon_embarrassed.gif" alt=":o" border="0" height="15" width="15">';
}
$str = preg_replace($find, $replace, $str);
return nl2br($str);
}
This works but now (if hide_smilies=0) some characters like " gets replaced with " and so on