<?
function bbcode($sText)
{
   $sTagArray['hr'] = array('tag'=>'<hr>');
   $sTagArray['eagudo'] = array('tag'=>'&eacute;');
   $atagArray['img'] = array('open'=>'<img src="','close'=>'" border="0">');
   $atagArray['b'] = array('open'=>'<b>', 'close'=>'</b>');
   $atagArray['i'] = array('open'=>'<i>', 'close'=>'</i>');
   $atagArray['u'] = array('open'=>'<u>', 'close'=>'</u>');
   $atagArray['table'] = array('open'=>'<table>', 'close'=>'</table>');
   $atagArray['td'] = array('open'=>'<td>', 'close'=>'</td>');
   $atagArray['tr'] = array('open'=>'<tr>', 'close'=>'</tr>');
   $atagArray['pre'] = array('open'=>'<tr>', 'close'=>'</pre>');
   $atagArray['esquerda'] = array('open'=>'<p align="left">', 'close'=>'</p>');
   $atagArray['direita'] = array('open'=>'<p align="right">', 'close'=>'</p>');
   $atagArray['centro'] = array('open'=>'<p align="center">', 'close'=>'</p>');
   $atagArray['sub'] = array('open'=>'<sub>', 'close'=>'</sub>');
   $atagArray['sup'] = array('open'=>'<sup>', 'close'=>'</sup>');
   $atagArray['citar'] = array('open'=>'<span style="font-size:8px;color:#FF6600;">QUOTE:</span><div class="quote">', 'close'=>'</div>');
   $atagArray['ftp=(.*)'] = array('open'=>'<a href="ftp://', 'close'=>'" target="iframek">\\1</a>');
   $atagArray['email=(.*)'] = array('open'=>'<a href="mailto:', 'close'=>'">\\1</a>');
   $atagArray['url=(.*)'] = array('open'=>'<a href="', 'close'=>'" target="iframe">\\2</a>');
   $atagArray['cor=(.*)'] = array('open'=>'<span style="color:', 'close'=>';">\\2</span>');
   $atagArray['tamanho=(.*)'] = array('open'=>'<span style="font-size:', 'close'=>';">\\2</span>');
   $atagArray['fonte=(.*)'] = array('open'=>'<span style="font-family:', 'close'=>';">\\2</span>');
   $atagArray['flash=(.*),(.*)'] = array('open'=>'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="\\1" height="\\2">
  <param name="movie" value="\\3">
  <param name="quality" value="high">
  <embed src="\\3" title="', 'close'=>'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="\\1" height="\\2"></embed></object>');
   

   foreach ($atagArray as $stagName => $replace)
   {
       $tagEnd = preg_replace("/\W/sUi", "", $stagName);

       $sText = preg_replace(
           "|\[$stagName\](.*)\[/$tagEnd\]|sUi",
           "$replace[open]\\1$replace[close]",
           $sText
       );
   }

   foreach ($sTagArray as $stagName => $replace)
   {
       if (eregi("[)(#$]", $stagName))
       {
           $stagNameNew = preg_replace("#([\)\(\$\#])#", "\\ \\1", $stagName);
           $stagNameNew = preg_replace("#( +)#", "", $stagNameNew);
           $sTagArray[ $stagNameNew ] = array('tag' => $replace['tag']);
           unset($sTagArray[ $stagName ]);
       }
   }
 
   foreach ($sTagArray as $stagName => $replace)
   {
       $sText= preg_replace("|\[$stagName\]|sUi", "$replace[tag]", $sText);
   }

   return $sText;
   
} 
?>