tags:

views:

385

answers:

1

For example,

how to get the character corresponding to 010F?

+5  A: 
header('Content-Encoding: UTF-8');

function mb_html_entity_decode($string)
{
    if (extension_loaded('mbstring') === true)
    {
     mb_language('Neutral');
     mb_internal_encoding('UTF-8');
     mb_detect_order(array('UTF-8', 'ISO-8859-15', 'ISO-8859-1', 'ASCII'));

     return mb_convert_encoding($string, 'UTF-8', 'HTML-ENTITIES');
    }

    return html_entity_decode($string, ENT_COMPAT, 'UTF-8');
}

function mb_ord($string)
{
    if (extension_loaded('mbstring') === true)
    {
     mb_language('Neutral');
     mb_internal_encoding('UTF-8');
     mb_detect_order(array('UTF-8', 'ISO-8859-15', 'ISO-8859-1', 'ASCII'));

     $result = unpack('N', mb_convert_encoding($string, 'UCS-4BE', 'UTF-8'));

     if (is_array($result) === true)
     {
      return $result[1];
     }
    }

    return ord($string);
}

function mb_chr($string)
{
    return mb_html_entity_decode('&#' . intval($string) . ';');
}

var_dump(hexdec('010F'));

var_dump(mb_ord('ó')); // 243
var_dump(mb_chr(243)); // ó
Alix Axel
Can you provide a run-able demo for your code?
Shore
Check my last edit.
Alix Axel