Welcome Guest ( Log In | Click here to Register a free account now! )
Welcome to Bleeping Computer, 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.| Important Announcement: The winners of the BC Million Post contest have been announced. You can read who the winners are at this post. - BleepingComputer Management |
![]() ![]() |
Dec 23 2005, 05:36 AM
Post
#1
|
|
|
New Member ![]() Group: Members Posts: 7 Joined: 28-August 05 Member No.: 32,518 |
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] Textpad - Maybe a macro could handle this.
$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; |
|
|
|
Jan 4 2006, 02:39 PM
Post
#2
|
|
|
New Member ![]() Group: Members Posts: 2 Joined: 4-January 06 Member No.: 48,616 |
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; |
|
|
|
![]() ![]() |
| Lo-Fi Version | Time is now: 22nd November 2008 - 08:40 AM |