Phpde Bbcode Kullanımı
/**************************
* 1. FONKSIYON
*************************/
<?php
function bb2html($text)
{
 $bbcode = array(”<”, “>”,
               “[list]“, “[*]“, “[/list]“,
               “[img]“, “[/img]“,
               “[b]“, “[/b]“,
               “[u]“, “[/u]“,
               “[i]“, “[/i]“,
               ‘[color=\"', "[/color]“,
               ‘[size=\"', "[/size]“,
               ‘[url=\"', "[/url]“,
               ‘[mail=\"', "[/mail]“,
               “[code]“, “[/code]“,
               “[quote]“, “[/quote]“,
               ‘\”]’);
 $htmlcode = array(”<”, “>”,
               “<ul>”, “<li>”, “</ul>”,
               ‘<img src=\”‘, “\”>”,
               “<b>”, “</b>”,
               “<u>”, “</u>”,
               “<i>”, “</i>”,
               ‘<span style=\”color:’, “</span>”,
               ‘<span style=\”font-size:’, “</span>”,
               ‘<a href=\”‘, “</a>”,
               ‘<a href=\”mailto:’, “</a>”,
               “<code>”, “</code>”,
               “<table width=100% bgcolor=lightgray><tr><td bgcolor=white>”, “</td></tr></table>”,
               ‘\”>’);
 $newtext = str_replace($bbcode, $htmlcode, $text);
 $newtext = nl2br($newtext);//second pass
 return $newtext;
}
//KULLANIMI
$yazi = “[b]php ve mysql[/b]“;
echo bb2html($yazi);
?>
/*****************
* 2. FONKSIYON
*****************/
<?php
//[php][/php] etiketleri içindeki kodlari renklendirir.
function bbcode($s)
{
$s = str_replace(”]n”, “]”, $s);
$match = array(’([php](.*?)[/php])se’);
$replace = array(”‘<div>’.highlight_string(stripslashes(’$1′), true).’</div>’”);
return preg_replace($match, $replace, $s);
}
$metin = “[php]<?php echo ‘PHP & MySQL’; ?>[/php]“;
echo bbcode($metin);
?>