I'm developing a CMS for a customer and he needs to edit stuff and use special characters such as ç
and ®
. However, I don't want him to have to enter the character codes like ®
. Does anyone knows a good way to automatically convert those characters using PHP?
The htmlentities() function converts characters to HTML entities.
Difference between htmlentities() and htmlspecialchars() function: The only difference between these function is that htmlspecialchars() function convert the special characters to HTML entities whereas htmlentities() function convert all applicable characters to HTML entities.
The htmlspecialchars() function converts special characters into HTML entities. It is the in-built function of PHP, which converts all pre-defined characters to the HTML entities.
You can use htmlentities() to do that.
php -r 'echo htmlentities("®ç", ENT_COMPAT, "UTF-8"), "\n";'
®ç
To turn entities back to readable text, use html_entity_decode():
php -r 'echo html_entity_decode("®ç", ENT_COMPAT, "UTF-8"), "\n";'
®ç
If you're not using unicode, omit the charset name or give the correct charset.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With