Help - Search - Members - Calendar
Full Version: Converting Html To Bbcode
BleepingComputer.com > Software > Programming
   
cambot001
I'm looking for an application or script to convert basic html tags to bbcode. Nothing fancy, just the commonly used tags for images, hyperlink, bold, etc. so I don't have to do it manually.

Google came up with a number of methods to convert bbcode to html, but not the other way around.

Unfortunately I'm not that well-versed with regular expressions. Maybe someone could give pointers?

Some options I have are:

PHP - This article, Simple and Complex BBcode with PHP, uses str_replace to convert bbcode to html:

CODE
$string = 'This is [b]cool[/b] - [url=http://www.tutorio.com]Tutorio.com Tutorials[/url]
$bb-replace = array ('/(\[[Bb]\])(.+)(\[\/[Bb]\])/','/(\[url=)(.+)(\])(.+)(\[\/url\])/');
$bb-replacements = array ('<b>\\2</b>','<a href="\\2">\\4</a>');
$string = preg_replace($bb-replace, $bb-replacements, $string);
print $string;
Textpad - Maybe a macro could handle this.
Eveccker
I have a simple bbcode parser for my website, you can look at it and learn a bit:
CODE
$string = "[b]bold['b'] [i]italic[/i] [u]underline[/u]";
$bb=array(
"[b]" => "<b>",
"[/b]" => "</b>",
"[i]" => "<i>",
"[/i]" => "</i>",
"[u]" => "<u>",
"[/u]" => "</u>",
);
$string = str_replace(array_keys($bb), array_values($bb), $s);
echo $string;
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.