PHP function help / beginner
<p>Look, if forum post have $hide_smilies is set to 1, I dont want the :p, :o to be replacen with images.</p>

<p>This is how I output forum post <code>bbcode($message);</code></p>

<p>And Function:</p>

<pre><code>function bbcode($str)
{
    $str = htmlentities($str);

    $find = array(
    "/:p/",
    "/:o/",
    '/\[b](.*?)\[\/b]/is',
    '/\[u](.*?)\[\/u]/is',
    '/\[i](.*?)\[\/i]/is'
    );

    $replace = array(
    '&lt;img src="/images/forum/icon_tongue.gif" alt=":p" border="0" height="15" width="15"&gt;',
    '&lt;img src="/images/forum/icon_embarrassed.gif" alt=":o" border="0" height="15" width="15"&gt;'
    '&lt;strong&gt;$1&lt;/strong&gt;',
    '&lt;u&gt;$1&lt;/u&gt;',
    '&lt;i&gt;$1&lt;/i&gt;',

    $str = preg_replace($find, $replace, $str);



    return nl2br($str);
</code></pre>

<p>Thanks</p>

<h1>Edit</h1>

<pre><code>function bbcode($str, $hide_smilies = 0)
{

$str = htmlentities($str);

$find = array(
    '/\[b](.*?)\[\/b]/is',
    '/\[u](.*?)\[\/u]/is',
    '/\[i](.*?)\[\/i]/is',
);


$replace = array(
    '&lt;strong&gt;$1&lt;/strong&gt;',
    '&lt;u&gt;$1&lt;/u&gt;',
    '&lt;i&gt;$1&lt;/i&gt;'
);

if ($hide_smilies == 0) 
{
    $find[] = "/:p/";
    $find[] = "/:o/";

    $replace[] = '&lt;img src="/images/forum/icon_tongue.gif" alt=":p" border="0" height="15" width="15"&gt;';
    $replace[] = '&lt;img src="/images/forum/icon_embarrassed.gif" alt=":o" border="0" height="15" width="15"&gt;';
}

$str = preg_replace($find, $replace, $str);


return nl2br($str);
}
</code></pre>

<p>This works but now (if hide_smilies=0) some characters like " gets replaced with <code>&amp;quot;</code> and so on</p>
