Why do many people use htmlentities & ENT_QUOTES?
To answer that question, I am providing you with a detailed explanation as to why htmlentities()
with the ENT_QUOTES
flag was used and should be used for a particular case such as this one.
Should there be a character such as '
with a string value of "O'Neil"
which in HTML source will reveal O'Neil
(something you should always do before doing anything) when using htmlentities()
with the ENT_QUOTES
flag, the unicode apostrophe will be inserted in the database, rather than O'Neil
without it, would not give the desired result.
Using htmlentities()
with the ENT_QUOTES
flag, ensures that the quote be entered in the database.
Using a prepared statement with this won't make a difference; it will still be entered as O'Neil
if htmlentities()
with the ENT_QUOTES
flag is not used.
That is why they used that. The source you got this from is unknown, so I can't put words in their mouth, but that is what that function is for.
I answered a similar question below, which you can consult further if you wish:
"Ok. well based on these comments it looks like htmlentities it not something really I need to worry about."
The above was pulled from a comment in another answer.
That said, it would probably be best to keep it since:
- It won't do any harm
- Should you get someone whose keyboard language uses unicode characters, then you're back to "square one" and you'll get unicodes entered, rather than the intended value(s).
That decision is yours.