note 81773 deleted from function.htmlentities by danbrown
| From: | danbrown@php.net | Date: | Sun, 17 May 2009 16:51:30 +0000 |
| Subject: | note 81773 deleted from function.htmlentities by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-154899@lists.php.net to get a copy of this message | ||
Note Submitter: richard at aggmedia dot net
----
From SR:
> There's no sane reason to use htmlentities() instead
> of htmlspecialchars(). As long as you specify the charset
> of a page with a Content-Type meta in the head of a
> page (which you should ALWAYS do in the first place),
> escaping all characters is completely pointless and will
> only grow the size of your page. Only the special HTML
> characters (<, >, &, etc.) need to be escaped, which is
> exactly what htmlspecialchars() does
This is inaccurate and unhelpful.
There are many cases where you would want to convert a UTF-8 (or other) encoded string into
appropriate HTML entity representations, as well as being just good practice to use more compatable
entities instead of embedded character encodings.
One such example is when using JavaScript for string manipulation, which doesn't support
character sets and thus does not respect the UTF-8 BOM. By converting to full entities, JavaScript
works with the entity text instead of byte codes.
So long as the developer understands what is happening with encoding and how character sets work,
they should make their own call on which function they need to use.