Html encode in PHP

Mathias F picture Mathias F · Dec 9, 2009 · Viewed 105.1k times · Source

What is the easiest way to Html encode in PHP?

Answer

Vallières picture Vallières · Dec 9, 2009

By encode, do you mean: Convert all applicable characters to HTML entities?

htmlspecialchars or htmlentities

You can also use strip_tags if you want to remove all HTML tags :

strip_tags

Note: this will NOT stop all XSS attacks