note 93378 added to function.html-entity-decode
| From: | MattRobinson at osu1 dot php dot net | Date: | Sun, 06 Sep 2009 21:11:04 +0000 |
| Subject: | note 93378 added to function.html-entity-decode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-160265@lists.php.net to get a copy of this message | ||
I wrote in a previous comment that html_entity_decode() only handled about 100 characters.
That's not quite true; it only handles entities that exist in the output character set (the
third argument). If you want to get ALL HTML entities, make sure you use ENT_QUOTES and set the
third argument to 'UTF-8'.
If you don't want a UTF-8 string, you'll need to convert it afterward with something like
utf8_decode(), iconv(), or mb_convert_encoding().
If you're producing XML, which doesn't recognise most HTML entities:
When producing a UTF-8 document (the default), then htmlspecialchars(html_entity_decode($string,
ENT_QUOTES, 'UTF-8'), ENT_NOQUOTES, 'UTF-8') (because you only need to escape
< and > and & unless you're printing inside the XML tags themselves).
Otherwise, either convert all the named entities to numeric ones, or declare the named entities in
the document's DTD. The full list of 252 entities can be found in the HTML 4.01 Spec, or you
can cut and paste the function from my site (http://inanimatt.com/php-convert-entities.php).
----
Server IP: 92.48.74.199
Probable Submitter: 87.194.221.55
----
Manual Page -- http://www.php.net/manual/en/function.html-entity-decode.php
Edit -- https://master.php.net/note/edit/93378
Del: integrated -- https://master.php.net/note/delete/93378/integrated
Del: useless -- https://master.php.net/note/delete/93378/useless
Del: bad code -- https://master.php.net/note/delete/93378/bad+code
Del: spam -- https://master.php.net/note/delete/93378/spam
Del: non-english -- https://master.php.net/note/delete/93378/non-english
Del: in docs -- https://master.php.net/note/delete/93378/in+docs
Del: other reasons-- https://master.php.net/note/delete/93378
Reject -- https://master.php.net/note/reject/93378
Search -- https://master.php.net/manage/user-notes.php