Bu fonksiyonlar ile phpde bbcode kullanabileceksiniz.
Kod:
/**************************
* 1. FONKSİYON
*************************/
<?php
function bb2html($text)
{
$bbcode = array("<", ">",
"
",
"[img]", "[/img]",
"
", "",
"
", "",
"
", "",
'[color="', "[/color]",
'[size="', "[/size]",
'[url="', "[/url]",
'[mail="', "[/mail]",
"
",
"
",
'"]');
$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 = "
php ve mysql";
echo bb2html($yazi);
?>
/*****************
* 2. FONKSİYON
*****************/
<?php
// etiketleri içindeki kodları renklendirir.
function bbcode($s)
{
$s = str_replace("]n", "]", $s);
$match = array('(
)se');
$replace = array("'<div>'.highlight_string(stripslashes('$1'), true).'</div>'");
return preg_replace($match, $replace, $s);
}
$metin = "
PHP- Kodu:
<?php echo 'PHP & MySQL'; ?>
";
echo bbcode($metin);
?>
www.end-onur.tr.gg