note 54927 added to function.htmlentities

From: Date: Tue, 19 Jul 2005 21:10:17 +0000
Subject: note 54927 added to function.htmlentities
Groups: php.notes 
Request: Send a blank email to php-notes+get-92186@lists.php.net to get a copy of this message
The existance of html entities such as &quot; inside an xml node causes most xml parsers to throw an error. The following function cleans an input string by converting html entities to valid unicode entities. <?php function htmlentities2unicodeentities ($input) { $htmlEntities = array_values (get_html_translation_table (HTML_ENTITIES, ENT_QUOTES)); $entitiesDecoded = array_keys (get_html_translation_table (HTML_ENTITIES, ENT_QUOTES)); $num = count ($entitiesDecoded); for ($u = 0; $u < $num; $u++) { $utf8Entities[$u] = '&#'.ord($entitiesDecoded[$u]).';'; } return str_replace ($htmlEntities, $utf8Entities, $input); } ?> So, an input of Copyrights &copy; make &quot;me&quot; grin &reg; outputs Copyrights &#169; make &#34;me&#34; grin &#174; ---- Manual Page -- http://www.php.net/manual/en/function.htmlentities.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+54927 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54927&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54927&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54927&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54927&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54927&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54927&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+54927&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#92186) next »