Jump to content

looking for bbcode class


carsten888

Recommended Posts

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;
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.