What are the differences between htmlspecialchars()
and htmlentities()
. When should I use one or the other?
You should use htmlspecialchars($strText, ENT_QUOTES)
when you just want your string to be XML and HTML safe:
For example, encode
However, if you also have additional characters that are Unicode or uncommon symbols in your text then you should use htmlentities() to ensure they show up properly in your HTML page.
Notes: