tags:

views:

57

answers:

2
+1  Q: 

PHP Basic BBcode

Heya!

I've managed to successfuly integrate BBCode, but I was wondering say if I wanted to dynamically list all the allowed/accepted BBCode - how would I be able to do that? (as it can be tedious manually writing out...and if the BBCode ever changed I'd have to update the writing)

I current have a BBCode() function, which contains 2 arrays, one which contains the regex, and the other which contains the replacements (html), and then I return a preg_replace() of the regex array with the replacement (html) array.

Cheers and looking forward to your inputs!

+1  A: 

Consider using a different markup language like Textile or Markdown. Simply saying that you support Markdown or Textile is decent enough; they're so widely used that users could easily look up the markup for them online.

Textile's syntax hasn't been updated since 2006, so it will likely remain very solid for years to come. Markdown's syntax hasn't been updated since 2004.

Both provide excellent PHP libraries:

mattbasta
A: 

If you have the allowed BBCodes in an array, an easy way to list it would be:

echo 'Allowed BBCode: ' . implode(', ', $bbcodes);
// (depends on how your $bbcode array is structured)

That being said, I disapprove of BBCode. It's not only user-unfriendly, it's also evil.

BBCode is a markup language invented by lazy programmers who didn't want to filter HTML the proper way. As a result, we now have a loose "standard" that's hard to implement. Filter your HTML the right way:

http://htmlpurifier.org/

NullUserException