PHP: How can I disable HTML content in user content?

I am launching a niche social networking site. I would like to ban HTML content in posts posted by the user; e.g. embedded videos etc. what option is there in php to clear this before I insert in db.

+7
source share
2 answers

There are three main solutions:

  • Remove all HTML tags from the message. In PHP, you can do this with the strip_tags() function.
  • Encode all characters, so if the user types in <b>hello</b> , it is displayed as <b>hello</b> . In PHP, this is htmlspecialchars() . (Note: in this situation, you usually save the content in the database as is, and use htmlspecialchars wherever you output the content.)
  • Use a sanitizer for HTML, such as an HTML cleaner . This allows users to use certain HTML formatting, such as bold / italics, but blocks malicious Javascript and any other tags that you want (i.e. <object> in your case).
+14
source

You can use the strip_tags() function.

+3
source

All Articles