carsten888 Posted September 21, 2009 Share Posted September 21, 2009 I'm looking for a class that deals with making html into bbcode and vise versa. And is able to close open tags and preferably configurable to choose which html-tags to ignore/delete. Googled for hours. anyone? Link to comment https://forums.phpfreaks.com/topic/175007-looking-for-bbcode-class/ Share on other sites More sharing options...
MadTechie Posted September 21, 2009 Share Posted September 21, 2009 Heres a simple function from BB to HTML <?php // Syntax Sample: // -------------- // [-img]http://phpfreaks.com/images/deadrats.gif[-/img] // [-url="http://phpfreaks.com"]phpfreaks[-/url] // [-mail="[email protected]"]Webmaster[-/mail] // [-size="25"]HUGE[-/size] // [-color="red"]RED[-/color] // [-b]bold[-/b] // [-i]italic[-/i] // [-u]underline[-/u] // [-list][-*]item[-*]item[-*]item[-/list] // [-code]value="123";[-/code] // [-quote]John said yadda yadda yadda[-/quote] // // Usage: // ------ // < ?php include 'bb2html.php'; ? > // < ?php $htmltext = bb2html($bbtext); ? > 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; } ?> Link to comment https://forums.phpfreaks.com/topic/175007-looking-for-bbcode-class/#findComment-922369 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.