htmlentities() bites the dust

Feb 10, 2004

I've used the PHP function htmlentities() for years, making my text safe to print to the screen and still remain XHTML Strict.

Well, all that changed today when I discovered the not only does htmlentities() make a string safe to print, it also translates UTF-8 encoded characters into so much gibberish.

So instead of htmlentities(), I now use htmlspecialchars() which only translates a select few characters. And looking back, unless there's a really, really, really good reason, you should always be using htmlspecialchars()

I learn something new every day :/


Comments closed

Recent posts

  1. Book Review - The Forever Man by Gordon R Dickson Jun 2025
  2. How to calculate the day of the week from a date... in your head Mar 2025
  3. Version 1.54 of the Virtual Keyboard Interface Javascript Released Nov 2024
  4. Customize Clipboard Content on Copy: Caveats Dec 2023
  5. Orcinus Site Search now available on Github Apr 2023

Archive