note 32157 added to function.utf8-encode
| From: | RoyLaw at 263 dot Net | Date: | Mon, 19 May 2003 09:16:43 +0000 |
| Subject: | note 32157 added to function.utf8-encode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-48569@lists.php.net to get a copy of this message | ||
There is a function for converting GB2312 code to Unicode code.It maybe useful for programming on
XML/WML in non-English lanaguages.
<?
// Program by sadly (www.phpx.com)
function gb2unicode($gb)
{
if(!trim($gb))
return $gb;
$filename="gb2312.txt";
$tmp=file($filename);
$codetable=array();
while(list($key,$value)=each($tmp))
$codetable[hexdec(substr($value,0,6))]=substr($value,9,4);
$utf="";
while($gb)
{
if (ord(substr($gb,0,1))>127)
{
$this=substr($gb,0,2);
$gb=substr($gb,2,strlen($gb));
$utf.="&#x".$codetable[hexdec(bin2hex($this))-0x8080].";";
}
else
{
$gb=substr($gb,1,strlen($gb));
$utf.=substr($gb,0,1);
}
}
return $utf;
}
?>
This function requires a code list of gb2312,you can download it at
ftp://ftp.unicode.org/Public/MAPPINGS/EASTASIA/GB/GB2312.TXT
----
Manual Page -- http://www.php.net/manual/en/function.utf8-encode.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32157
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32157&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32157&report=yes