Home > Backend Development > PHP Tutorial > About BIG5-HKSCS solution_PHP tutorial

About BIG5-HKSCS solution_PHP tutorial

WBOY
Release: 2016-07-21 15:55:29
Original
1254 people have browsed it

It was very frustrating to find that PHP has always supported the HSCCS problem that has always been bothering me. But the name is not HK-SCS, but BIG5-HKSCS.
The following is the solution for HK's supplementary character set:
Set the HTML page to UTF-8,
Before writing to the database: iconv('big5-hkscs','utf8', $string)
If you need to convert to UNICODE, use the following function
function String2Unicode($data, $language)
{
$data = nl2br(trim($data));
$data = str_replace('< ;br />',chr(13),$data);
$str = '';
preg_match_all("/[x80-xff]?./",$data,$ar);
debug($ar);
foreach($ar[0] as $v)
{
if($v != '' && $v!=chr(13))
{
$str .= "".utf82unicode(iconv($language,"UTF-8",$v)).";";
}else {
$str .=$v ;
}
}
return $str;
}
function utf82unicode($c) {
switch(strlen($c)) {
case 1:
return ord($c);
case 2:
$n = (ord($c[0]) & 0x3f) << 6;
$n += ord($c[ 1]) & 0x3f;
return $n;
case 3:
$n = (ord($c[0]) & 0x1f) << 12;
$n += (ord($c[1]) & 0x3f) << 6;
$n += ord($c[2]) & 0x3f;
return $n;
case 4:
$n = (ord($c[0]) & 0x0f) << 18;
$n += (ord($c[1]) & 0x3f) << 12;
$n += (ord($c[2]) & 0x3f) << 6;
$n += ord($c[3]) & 0x3f;
return $n;
}
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/318279.htmlTechArticleI was very distressed to find that PHP has always supported the HSCCS problem that has been bothering me. But the name is not HK-SCS, but BIG5-HKSCS. The following is the solution for the HK supplementary character set: Set the HTML page to...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template