Re: Converting "\u00F4" style characters

Asgeir Frimannsson <[email protected]>
Newsgroups gmane.comp.php.internationalization
Message-ID <[email protected]>
Michael Wallner wrote:
> it seems that the function doesn't work with higher
> values like "\u20AC" which is the EUR symbol :-(

Hi Mike,

it's most probably the font you're using that does not have support for the
EUR symbol. I tested the following on my box, and it displays fine:

<?php
    function unichr($hex)
    {
        $utf = '';
        $hex = hexdec((substr($hex, 0,2) === '\\u') ? substr($hex, 2) :
$hex);
        
        if ($hex < 128) {
            $utf = chr($hex);
        } elseif ($hex < 2048) {
            $utf .= chr(192 + (($hex - ($hex % 64)) / 64));
            $utf .= chr(128 + ($hex % 64));
        } else {
            $utf .= chr(224 + (($hex - ($hex % 4096)) / 4096));
            $utf .= chr(128 + ((($hex % 4096) - ($hex % 64)) / 64));
            $utf .= chr(128 + ($hex % 64));
        }
        return $utf;
    }
    header('Content-Type: text/plain; charset: utf-8');
    print unichr('\\u20AC');
?>

Most fonts (used to) only have the iso 8859-1 characters, and the EUR symbol
is only added in iso 8859-15.

Hope that solves your problem... 

Keep up the good work :)

regards,
asgeir

-- 
PHP Internationalization Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.