is there a built-in function to render characters like ' as identities (’) ?
also, is it unsafe to output raw characters (e.g ') in the html?
thanks.
Try htmlentities()
:
htmlentities("'", ENT_QUOTES, 'UTF-8', true);
Regarding your second question, yes (as a general rule).
To output user input / raw input you should always use htmlspecialchars()
at least.
You're looking for htmlentities(). It will translate any character that has a HTML character entity equivalent.
It is not unsafe to output raw characters in your HTML, although there are a couple of caveats to that: