Jump to content


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.

Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.


Converting Html To Bbcode

  • Please log in to reply
1 reply to this topic

#1 cambot001


  • Members
  • 7 posts
  • Local time:01:13 AM

Posted 23 December 2005 - 05:36 AM

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:

$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.

BC AdBot (Login to Remove)


#2 Eveccker


  • Members
  • 2 posts
  • Local time:10:13 PM

Posted 04 January 2006 - 02:39 PM

I have a simple bbcode parser for my website, you can look at it and learn a bit:
$string = "[b]bold['b'] [i]italic[/i] [u]underline[/u]";
"[b]" => "<b>",
"[/b]" => "</b>",
"[i]" => "<i>",
"[/i]" => "</i>",
"[u]" => "<u>",
"[/u]" => "</u>",
$string = str_replace(array_keys($bb), array_values($bb), $s);
echo $string;

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users