Page 1 of 1

Seriously annoying encoding issue which I can't fix!!!

Posted: Sun Jan 25, 2009 4:58 am
by Walid
Although the utf-8 code units for the Euro sign (€) are "E2 82 AC", the following code returns "C2 80":

Code: Select all

 
<?
    function str2hex ( $string ) 
    {
        for  ( $i = 0; $i < strlen ( $string ) ; $i++ )  $result .= str_pad ( dechex  ( ord ( $string[$i] )  ) , 2, 0, STR_PAD_LEFT ) ;
        return $result;
    }
 
    echo str2hex(utf8_encode("€"));
?>
 
http://bugs.php.net/bug.php?id=22277 says:
utf8_encode() only supports iso-8859-1 to UTF-8 conversion, whilst the charset that covers euro sign is iso-8859-15. Try iconv extension instead.
I've tried using iconv as well, but to no avail.

Can anyone please tell me how I get from the Euro sign to "E2 82 AC"?

Many thanks.

Re: Seriously annoying encoding issue which I can't fix!!!

Posted: Sun Jan 25, 2009 5:39 am
by requinix
I doubt they'd give advice that doesn't work.

What's the code you tried with iconv?

Re: Seriously annoying encoding issue which I can't fix!!!

Posted: Sun Jan 25, 2009 5:51 am
by Walid
The advice wasn't directed to me.

I've tried the following:

Code: Select all

 
$Latin1 = "€";
$Latin2 = iconv("ISO-8859-1", "ISO-8859-15", $Latin1 );
$UTF8   = iconv("ISO-8859-15", "UTF-8", $Latin2 );
echo str2hex($UTF8);
 
As well as:

Code: Select all

 
$Latin1 = "€";
$UTF8   = iconv("ISO-8859-15", "UTF-8", $Latin1 );
echo str2hex($UTF8);