Retorno: String
Descrição: Chame a função passando o texto no qual as tags terão de ser trocadas por tags html.
Bibliotecas: Nenhuma
Limitações: PHP 4.0+
Função:
<?php
/**
* Função apenas modificada por:
* Felipe Nascimento (Eclesiastes)
**/
function bbcode($sText)
{
$sTagArray['B)'] = array('tag'=>'<img src="xx.gif">');
$sTagArray['o}o'] = array('tag'=>'<img src="xx.gif">');
$sTagArray['br'] = array('tag'=>'<br>');
$sTagArray['hr'] = array('tag'=>'<hr>');
$atagArray['img'] = array('open'=>'<img src="','close'=>'">');
$atagArray['b'] = array('open'=>'<b>', 'close'=>'</b>');
$atagArray['i'] = array('open'=>'<i>', 'close'=>'</i>');
$atagArray['u'] = array('open'=>'<u>', 'close'=>'</u>');
$atagArray['url'] = array('open'=>'<a href="', 'close'=>'" target="_blank">\\1</a>');
$atagArray['email'] = array('open'=>'<a href="mailto:', 'close'=>'">\\1</a>');
$atagArray['url=(.*)'] = array('open'=>'<a href="', 'close'=>'" target="_blank">\\2</a>');
$atagArray['email=(.*)'] = array('open'=>'<a href="mailto:', 'close'=>'">\\2</a>');
$atagArray['color=(.*)'] = array('open'=>'<font color="', 'close'=>'">\\2</font>');
$atagArray['size=(.*)'] = array('open'=>'<font size="', 'close'=>'">\\2</font>');
$atagArray['font=(.*)'] = array('open'=>'<font face="', 'close'=>'">\\2</font>');
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;
}
?>Exemplo de chamada:
print bbcode("[B)][o}o] [b]teste[/b]");










