Matthew James Taylor
Matthew James Taylor

Reputation: 4866

Are there any code libraries that validate/convert blog comments to XHTML strict?

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?

Upvotes: 0

Views: 214

Answers (2)

elviejo79
elviejo79

Reputation: 4600

I personally think that it 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 it 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 syntax 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.

Upvotes: 3

jimiyash
jimiyash

Reputation: 2494

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

Upvotes: 0

Related Questions