[thelist] Web Character Sets

kasimir-k evolt at kasimir-k.fi
Wed Mar 22 02:19:36 CST 2006


> http://www.volkanozcelik.com/cre8/blog/2006/03/ajax-and-charset-conversion.html


This reminded me of some Ajax/PHP/euro-sign -issues I had recently. 
UTF-8 and PHP is not always without problems, so I some times use 
ISO-8859-1 or ISO-8859-15. The problem with ISO-8859-1 is that it 
doesn't include the € character (euro).

Indeed Javascript is sending stuff to server with UTF-8 encoding, and it 
would be very easy to just
$str = mb_convert_encoding ($str, 'ISO-8859-15' , 'UTF-8');

Unfortunately on one server I didn't have the mb-extensions, so I had to 
come up with something else:
$str = str_replace(chr(0xE2) . chr(0x82) . chr(0xAC), chr(0xA4), $str);
$str = utf8_decode($str);

UTF-8 represents the euro sign with bytes E2, 82, AC. ISO-8859-15 uses 
the byte A4.
utf8_decode converts the UTF-8 string to ISO-8859-1, but I can display 
the result as ISO-8859-15 and get the characters I'm interested in show 
correctly (Ä, Ö etc.)

As you can see everything is much simpler if you can just use UTF-8 all 
the way.

hth,
.k



More information about the thelist mailing list