views:

121

answers:

3

I am working on a website in PHP where people can make comments similar to a blog, and I only want particular tags to be allowed. Are there any pre-built libraries that process comments and produce valid XHTML Strict code? I would need to do this in JavaScript so I can generate a live preview like Stack Overflow, plus in PHP before saving it to a MySQL database.

The allowed HTML tags will be: strong, em, blockquote, and links (rel=nofollow not required)

One way would be to allow people to directly enter the HTML into the comment field but I would prefer to use a simple mark up something like this (can be different - this is an example):

*strong*
_em_
[blockquote]
http://www.link.com

I want line breaks to be converted to <br />.

Are there any code libraries that do the above?

A: 

Not sure if this fits your needs, but check out fckeditor, or tinymce.

jimiyash
Thanks jason but these are way too complicated - I need a very simple solution that doesn't need a menu of controls etc.
Matthew James Taylor
+3  A: 

I personally think that is better to allow normal html tags. Yet another markup with its own little variations is less usable.

Jakob's Law of the Web User Experience states that: "users spend most of their time on other websites."

So you need to do stuff like most other sites do.

That leaves you with:

  • HTML -> Use HTML Purifier to filter just the tags you want. I like this method.
  • Markdown -> This sintax is similar to what you want and stackoverflow uses it. You can parse it with PHP Markdown
  • BBCode -> I don't have experience with this but in php 5.2 seems to come already installed: PHP BBCode or there are older libraries to parse it.
elviejo
Thanks elviejo, it looks like HTML Purifier is exactly what I need.
Matthew James Taylor
Markdown is what SO uses; Wikipedia uses its own, more-or-less unique markup.
Ben Blank
Corrected Ben thanks.
elviejo
A: 

Thanks My Friend

Guncel Blog