What is the easiest way to Html encode in PHP?
+6
A:
By encode, do you mean : Convert all applicable characters to HTML entities?
http://ca3.php.net/manual/en/function.htmlentities.php
You can also use strip_tags if you want to remove all HTML tags :
valli-R
2009-12-09 13:16:09
I am not shure which I have to use. I need this to avoid XSS-atacks.
Malcolm Frexner
2009-12-09 13:23:50
Then htmlspecialchars should do the trick. Or use filter_var with the FILTER_SANITIZE_SPECIAL_CHARS filter.
Arkh
2009-12-09 13:28:42
`htmlspecialchars` > `htmlentities` in most cases. HTML entities for non-ASCII characters should be a thing of the past; just use UTF-8 and drop the characters straight in.
bobince
2009-12-09 14:55:22
A:
I think he means the php equivalent to the ASP.NET method "htmlencode". It is used to sanatize the input by replacing characters like '<' with <. He doesn't want to strip them away.
Richard
2010-09-23 23:40:06