note 96324 deleted from function.html-entity-decode by salathe

From: Date: Tue, 22 Jun 2010 07:51:52 +0000
Subject: note 96324 deleted from function.html-entity-decode by salathe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-170367@lists.php.net to get a copy of this message
Note Submitter: dev dot stn at gmail dot com ---- If you want to convert Hex or Decimal Html entities into UTF-8 HTML entities : Example : &#xE9; into é OR &#233; into é Use this function : <?php function numeric_entities($string){ $mapping_hex = array(); $mapping_dec = array(); foreach (get_html_translation_table(HTML_ENTITIES, ENT_QUOTES) as $char => $entity){ $mapping_hex[html_entity_decode($entity,ENT_QUOTES,"UTF-8")] = '&#x' . strtoupper(dechex(ord(html_entity_decode($entity,ENT_QUOTES)))) . ';'; $mapping_dec[html_entity_decode($entity,ENT_QUOTES,"UTF-8")] = '&#' . ord(html_entity_decode($entity,ENT_QUOTES)) . ';'; } $string = str_replace(array_values($mapping_hex),array_keys($mapping_hex) , $string); $string = str_replace(array_values($mapping_dec),array_keys($mapping_dec) , $string); return $string; } ?>

« previous php.notes (#170367) next »