note 45886 deleted from function.utf8-encode by tomsommer
| From: | tomsommer@php.net | Date: | Wed, 22 Sep 2004 19:30:32 +0000 |
| Subject: | note 45886 deleted from function.utf8-encode by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-77189@lists.php.net to get a copy of this message | ||
Note Submitter: ng4rrjanbiah at rediffmail dot com
----
Here is a code to convert ISO 8859-1 to UTF-8 and vice versa without using utf8_encode() and
utf8_decode().
<?php
//Logic from http://twiki.org/cgi-bin/view/Codev/InternationalisationUTF8
$str_iso8859_1 = 'foo in ISO 8859-1';
//ISO 8859-1 to UTF-8
$str_utf8 = preg_replace("/([\x80-\xFF])/e",
"chr(0xC0|ord('\\1')>>6).chr(0x80|ord('\\1')&0x3F)",
$str_iso8859_1);
//UTF-8 to ISO 8859-1
$str_iso8859_1 = preg_replace("/([\xC2\xC3])([\x80-\xBF])/e",
"chr(ord('\\1')<<6&0xC0|ord('\\2')&0x3F)",
$str_utf8);
?>
HTH,
R. Rajesh Jeba Anbiah