BBCode Replacement Script
Posted By: missionsix on Mar 06, 2005
Add a replace bbcode function to your scripts
Ever want to add your own bbcode to your web blog or site without all the hassles of coding? Well, now you can. I'll go into more depth later, but heres the function:
Now when you want to parse a string, or form to convert bbcode to html...
OUTPUT:
html: hi this is <b>Bold</b>
parsed html: hi this is Bold
!!!!
GO USE IT!
PHP Code:
function BBCODE($bbcode)
{
//the bbcode tags..
$bbc_a=array("[str]","[/str]","[b]","[/b]","[u]","[/u]","[big]","[/big]","[huge]","[/huge]","[email]","[/email]","[url]","[/url]","[red]","[/red]","[orange]","[/orange]","[green]","[/green]","[blue]","[/blue]");
//bbcode gets converted to..
$bbc_b=array("<strike>","</strike>","<b>","</b>","<u>","</u>","<font size=4>","</font>","<font size=8>","</font>","<a href=\"mailto:","\">E-MAIL LINK</a>","<a href=\"","\" target=\"blank\">WEB LINK</a>","<font color=#ff6666>","</font>","<font color=#ffaa66>","</font>","<font color=#66ff66>","</font>","<font color=#6666ff>","</font>");
$bbc_num=count($bbc_a);
$loop=0;
while($loop<$bbc_num)
{
$bbcode=str_replace($bbc_a[$loop], $bbc_b[$loop], $bbcode);
$loop++;
}
return $bbcode;
}
PHP Code:
$string = "hi this is [b]BOLD[/b]";
$string = BBCODE($string);
echo $string;
html: hi this is <b>Bold</b>
parsed html: hi this is Bold
!!!!
GO USE IT!
