shyish Posted June 15, 2010 Share Posted June 15, 2010 I have my BBCode parser: <?php // A simple FAST parser to convert BBCode to HTML // Trade-in more restrictive grammar for speed and simplicty // // Syntax Sample: // -------------- // [img=http://elouai.com/images/star.gif] // [url="http://elouai.com"]eLouai[/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"; // John said yadda yadda yadda // // Usage: // ------ // <?php include 'bb2html.php'; ?> // <?php $htmltext = bb2html($bbtext); ?> // // (please do not remove credit) // author: Louai Munajim // website: http://elouai.com // date: 2004/Apr/18 function bb2html($text) { $bbcode = array("<", ">", " ", " ", " ", "", "", "", "", "", "", "", '", "", '", "[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; } ?>[/code] I have it included. include 'inc/bbcode.php'; But I just don't really know where to go next. I'm trying to convert the BBCode in the news on my homepage which is loaded from the forums into HTML. That's called via <?PHP echo $post; ?> Still no idea what now to actually convert it onload, as at the moment it's doing nothing. Thanks, Shyish Link to comment https://forums.phpfreaks.com/topic/204900-bbcode-help/ Share on other sites More sharing options...
Soldier Jane Posted June 15, 2010 Share Posted June 15, 2010 I think you need to edit your post a bit. Link to comment https://forums.phpfreaks.com/topic/204900-bbcode-help/#findComment-1072703 Share on other sites More sharing options...
kratsg Posted June 15, 2010 Share Posted June 15, 2010 Well, you have a function: $new_text = bb2html($text); This function returns the replaced text (from what I can tell). Simply place text ($text) to convert to HTML in there and then echo out the results ($new_text). Link to comment https://forums.phpfreaks.com/topic/204900-bbcode-help/#findComment-1072709 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.