tags:

views:

1882

answers:

3
+2  Q: 

Html encode in PHP

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 :

http://ca2.php.net/manual/en/function.strip-tags.php

valli-R
I am not shure which I have to use. I need this to avoid XSS-atacks.
Malcolm Frexner
Then htmlspecialchars should do the trick. Or use filter_var with the FILTER_SANITIZE_SPECIAL_CHARS filter.
Arkh
`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
A: 

Perhaps you mean this: htmlentities on php.net

Tim
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