note 85884 deleted from function.htmlentities by cmb
| From: | cmb@php.net | Date: | Sun, 01 Dec 2019 08:31:41 +0000 |
| Subject: | note 85884 deleted from function.htmlentities by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-213297@lists.php.net to get a copy of this message | ||
Note Submitter: Kenneth Kin Lum
----
use htmlspecialchars() if you are passing in a usual ASCII string. It is faster than
htmlentities().
For example, if you are just doing
htmlentities('<div style="background: #fff"></div>');
then you can just use htmlspecialchars(). htmlentities() will look for all possible ways to convert
string into html entities, such as © or é (which is e with an acute accent on
top).
Note that ASCII is just 7 bit, which is 0x00 to 0x7F. htmlspecialchars() will handle characters
inside this range already. htmlentities() is for the 8-bit Latin-1 (ISO-8859-1) to handle European
characters, or for UTF-8 when the 3rd argument is "UTF-8" to handle UTF-8 characters, or
other types of encodings using different values for the 3rd argument passed into htmlentities().