Converting HTML To BBCode

March 7, 2006 on 9:01 pm | In PHP |

I am currently learning PHP, so I set out to write an application which would convert my HTML-coded tutorials into BBCode suitable for forums. That goes without saying that my code failed miserably.. I was not too far off though; I got the general gist of it. So, I decided to ask the wonderful guys and gals on the ‘General user’ PHP mailing list (which, by the way, means what it says about being of very high volume!), and they came up with a solution.

The solution involved regular expressions (or reg-exp, for the abbreviation fanatics out there) - which I am proud to say I understood none of. :D Hopefully I’ll soon be onto regular expressions so that I can figure out what it means - I remember the days I thought HTML was cryptic! How naïve I was.. Reg-exp is impossible to understand in my opinion, although I’m sure the more advanced PHP coders among you will say the contrary.

Enough of my rambling - here’s the page you can use if you ever want to translate HTML code into forum-usable BBCode: HTML To BBCode.

Note: Only the following tags (and their closing ones) are currently supported -

  • <strong>
  • <b>
  • <em>
  • <i>
  • <ul>
  • <ol>
  • <li>
  • <a>
  • <img>

It works surprisingly well - although note: outputted BBCode may be different to the BBCode used on some forums. BBCode which is returned by this script is proven to work on vBulletin forums.

HTMLtoBBCode Converter Source Code

28 Comments »

RSS feed for comments on this post. TrackBack URI

  1. Excellent app. I occasionally get sent submissions in HTML that need converting so I may well use and abuse this!

    Comment by ray — March 9, 2006 #
    Using Mozilla Firefox Mozilla Firefox 1.5.0.1 on Windows Windows XP

  2. A great app to have. I thought of creating a BBCode parser myself for my CMS although I think HTML is better for a CMS because you’re building a site and you shouldn’t limit yourself to BBCode.

    Comment by hari — March 10, 2006 #
    Using Mozilla Firefox Mozilla Firefox 1.0.7 on Debian GNU/Linux Debian GNU/Linux

  3. Ray - Hehe, no problem! ;)

    Hari - Thanks :D You’re right, HTML is probably a better choice for the CMS - it gives the user much more freedom than sticking to BBCode tags. Plus, with HTML there’s always room to expand the CMS with new tricks - with BBCode, any new implementations would be a bit more complex. At least that’s MHO :)

    Comment by J_K9 — March 10, 2006 #
    Using Internet Explorer Internet Explorer 6.0 on Windows Windows XP

  4. If you want a visual regular expression editor you can use KRegExpEditor. It’s very easy to build regular expressions if you understand the logic behind what you want. You needn’t worry about the syntax. This tool will generate it for you.

    Comment by hari — March 11, 2006 #
    Using Mozilla Firefox Mozilla Firefox 1.0.7 on Debian GNU/Linux Debian GNU/Linux

  5. Hm do you know where i can find a translator that works the other way aka bbcode to html

    Comment by 2rzn — May 15, 2006 #
    Using Mozilla Firefox Mozilla Firefox 1.5.0.3 on Windows Windows XP

  6. Forget it i found one myself at :http://hometown.aol.co.uk/JRMC137/BBCode2HTML/index.htm

    Comment by 2rzn — May 15, 2006 #
    Using Mozilla Firefox Mozilla Firefox 1.5.0.3 on Windows Windows XP

  7. Thanks for sharing it :)

    Comment by J_K9 — May 15, 2006 #
    Using Internet Explorer Internet Explorer 6.0 on Windows Windows XP

  8. Very nice, but why dont u remove the html tags that can’t be converted? such as table and td? Just leave the bbcode with the working ones.

    Comment by R2 — June 16, 2006 #
    Using Opera Opera 8.54 on Windows Windows XP

  9. Thank you.

    That is a good point.. I think the original idea was that, because there are so many different variations of BBCode, those HTML tags which were not converted were left in the code so that the user could then convert those themself if their forum’s BBCode allowed it.

    But, I do see your point - once I’ve furthered my knowledge of reg-exp (or, rather, get to the holidays so I can refresh my memory!), I will add the option to do that.

    Thanks for the input! ;)

    Comment by J_K9 — June 16, 2006 #
    Using Internet Explorer Internet Explorer 6.0 on Windows Windows XP

  10. How do i download this code to try it myself?
    I dont see no link around here to download the code

    Comment by xac — May 10, 2007 #
    Using Mozilla Firefox Mozilla Firefox 2.0.0.3 on Windows Windows XP

  11. That’s a good point - I haven’t put a link to a downloadable file :?

    I’ll do it this afternoon and email you a link ;)

    Comment by J_K9 — May 10, 2007 #
    Using Mozilla Firefox Mozilla Firefox 2.0.0.3 on Windows Windows Vista

  12. Hello! Help solve the problem.
    Very often try to enter the forum, but says that the password is not correct.
    Regrettably use of remembering. Give like to be?
    Thank you!

    Comment by AltaGid — August 8, 2007 #
    Using Opera Opera 7.54 on Windows Windows XP

  13. Oh that is such a nice app.! It works perfectly and it’s very usefull for uploading very much images or stuff like that on a forum!
    Thank you very much for sharing it.

    Comment by Levina — August 11, 2007 #
    Using Internet Explorer Internet Explorer 7.0 on Windows Windows XP

  14. juego de azar póquer juego…

    ?…

    Trackback by juego de azar póquer juego — February 10, 2008 #
    Using Internet Explorer Internet Explorer 6.0 on Windows Windows Server 2003

  15. foreclosure home loan…

    playboy teaspoon palming?Brighton expeditions.manpower,…

    Trackback by foreclosure home loan — February 15, 2008 #
    Using Internet Explorer Internet Explorer 6.0 on Windows Windows XP

  16. bingo games in chicago illinois…

    deemphasizing secretariat?prudential Socratic eleventh …

    Trackback by bingo games in chicago illinois — February 15, 2008 #
    Using Opera Opera 5.11 on Windows Windows ME

  17. nebraska national life insurance company…

    tattoos,plodding,Galilean,Russo Timonize abstractionism …

    Trackback by nebraska national life insurance company — February 17, 2008 #
    Using Internet Explorer Internet Explorer 6.0 on Windows Windows Server 2003

  18. sport book betting guide…

    airlift!Kruse aerodynamic logic embryos!ballplayers …

    Trackback by sport book betting guide — February 17, 2008 #
    Using Internet Explorer Internet Explorer 5.0 on Mac OS Mac OS

  19. ultimate bet download…

    royalty absolving:eventfully!…

    Trackback by ultimate bet download — February 22, 2008 #
    Using Internet Explorer Internet Explorer 6.0 on Windows Windows XP

  20. Excelent app!
    where i can download sourse code? ;-)

    Comment by crond — February 28, 2008 #
    Using Mozilla Firefox Mozilla Firefox 2.0.0.12 on Windows Windows XP

  21. b4c3b5ff8465…

    b4c3b5ff84657beecbae…

    Trackback by b4c3b5ff8465 — May 12, 2008 #
    Using Unknown browser

  22. Oxycontin….

    Oxycontin withdrawal home remedies. Oxycontin lawyer columbus. Can not stop oxycontin. Oxycontin. Oxycontin no prescription….

    Trackback by Oxycontin overseas pharmacy. — May 30, 2008 #
    Using Unknown browser

  23. car insurance orange county…

    beefing Lyra,diet.brownies …

    Trackback by car insurance orange county — May 31, 2008 #
    Using Internet Explorer Internet Explorer 6.0 on Windows Windows Server 2003

  24. slotsvillage…

    humiliations!maced Hesse!Fafnir:fortuitously …

    Trackback by slotsvillage — July 20, 2008 #
    Using Opera Opera 5.11 on Windows Windows ME

  25. Fat tits cumshot….

    Fat tits cumshot….

    Trackback by Fat tits cumshot. — July 20, 2008 #
    Using Unknown browser

  26. grattis poker kort spel…

    muddled encircles phoenix:Datsun barks …

    Trackback by grattis poker kort spel — July 20, 2008 #
    Using Internet Explorer Internet Explorer 6.0 on Windows Windows XP

  27. Good job of research. Thanks for the informative post.

    Comment by Hot Tattoo Designs — August 12, 2008 #
    Using Internet Explorer Internet Explorer 7.0 on Windows Windows XP

  28. Incest….

    Incest….

    Trackback by Incest. — October 15, 2008 #
    Using Unknown browser

Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>

Powered by WordPress with Pool theme.
Entries and comments feeds. Valid XHTML and CSS. ^Top^
0.587 seconds.

Cheap Gas - Debt Consolidation - Credit Counseling - Arizona Landscaping