gtal3x Posted October 31, 2007 Share Posted October 31, 2007 Can someone give me an example of how the BB Code works? Basicly I have a page were users add comments... I got all the nessesery options like B I U Image Link, Smiles... Now when the comment has been posted how can i change all those [b][i][u] :-) into html code and images... Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/75443-solved-bb-code/ Share on other sites More sharing options...
cooldude832 Posted October 31, 2007 Share Posted October 31, 2007 try this <?php function bb2html($text) { $bbcode = array("<", ">", \\"[list]", "[*]", "[/list]", \\"[img=", "]", \\"[b]", "[/b]", \\"[u]", "[/u]", \\"[i]", "[/i]", \\'[color="', "[/color]", \\"[size=\"", "[/size]", \\'[url="', "[/url]", \\"[mail=\"", "[/mail]", \\"[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; } ?> You can add more tags if you want later Oops i need to escape it, so remove all the esacpings[/code] Link to comment https://forums.phpfreaks.com/topic/75443-solved-bb-code/#findComment-381659 Share on other sites More sharing options...
gtal3x Posted October 31, 2007 Author Share Posted October 31, 2007 Thanx a lot Link to comment https://forums.phpfreaks.com/topic/75443-solved-bb-code/#findComment-381668 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.