note 45886 added to function.utf8-encode
| From: | ng4rrjanbiah at rediffmail dot com | Date: | Wed, 22 Sep 2004 14:07:34 +0000 |
| Subject: | note 45886 added to function.utf8-encode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-77156@lists.php.net to get a copy of this message | ||
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
----
Manual Page -- http://www.php.net/manual/en/function.utf8-encode.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+45886
Delete -- http://master.php.net/manage/user-notes.php?action=delete+45886&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+45886&report=yes
Search -- http://master.php.net/manage/user-notes.php