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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Walid
Forum Commoner
Posts: 33
Joined: Mon Mar 17, 2008 8:43 am

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

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

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

Post by requinix »

I doubt they'd give advice that doesn't work.

What's the code you tried with iconv?
Walid
Forum Commoner
Posts: 33
Joined: Mon Mar 17, 2008 8:43 am

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

Post 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);
 
Post Reply