PHP function bbcode make optional to replace smileys
<p>I want to give the oppurtunity to the user if he wants his smileys to be replaced with image smileys.</p>

<p>I tried this.</p>

<p><code>bbcode($text, TRUE);</code></p>

<pre><code>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) {
     '&lt;img src="/img/toungue.gif"&gt;',
  }
  '&lt;strong&gt;$1&lt;/strong&gt;',
  '&lt;u&gt;$1&lt;/u&gt;',
  '&lt;i&gt;$1&lt;/i&gt;',
  '&lt;img src="$1" alt="$1" /&gt;',
  '&lt;a href="$1" target="_blank" rel="nofollow" title="$1"&gt;$1&lt;/a&gt;',
  '&lt;span style="color:$1"&gt;$2&lt;/span&gt;',
  '&lt;span style="font-size:$1"&gt;$2&lt;/span&gt;'
 );

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



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

<p>I guess u cant have if clause in array.</p>

<p>And i also tried:</p>

<pre><code>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(
'&lt;strong&gt;$1&lt;/strong&gt;',
'&lt;u&gt;$1&lt;/u&gt;',
'&lt;i&gt;$1&lt;/i&gt;',
'&lt;img src="$1" alt="$1" /&gt;',
'&lt;a href="$1" target="_blank" rel="nofollow" title="$1"&gt;$1&lt;/a&gt;',
'&lt;span style="color:$1"&gt;$2&lt;/span&gt;',
'&lt;span style="font-size:$1"&gt;$2&lt;/span&gt;'
);

if ($smileys == true) {

 $find = array(
 ':p'
);

 $replace = array(
 '&lt;img src="/img/toungue.gif"&gt;'
);
}

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



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

<p>Equals to = No ending delimiter ':' found in functions.php on line 68</p>
