Jump to content

BBCode help


shyish

Recommended Posts

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

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.