note 96324 modified in function.html-entity-decode by thiago

From: Date: Mon, 22 Feb 2010 02:37:59 +0000
Subject: note 96324 modified in function.html-entity-decode by thiago
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-166238@lists.php.net to get a copy of this message
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; } ?> --was-- If you want to convert Hex or Decimal Html entities into UTF-8 HTML entities : Example : &#xE9; into é OR &#233; into é Use this function : 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; } http://php.net/manual/en/function.html-entity-decode.php

« previous php.notes (#166238) next »