Use of coded tables (1)

Source: Internet
Author: User
Coding <?php
/**
* When the coded comparison is made, it is not immediately available and needs to be processed.
* Of course, simple look-up table is possible, but not efficient.
* Now take simplified conversion as an example to illustrate the use of the comparison table
*/

/**
* Connect and open the comparison table
*/
$conn = mysql_connect ();
mysql_select_db ("Unicode");
/**
* Extract Big5 and GBK encoded in the table with only 13,487 Big5 (including symbols)
*/
$sql = "Select gbk,big5,gb2312 from Unicode where Big5!= '";
$sql = "SELECT * from Unicode";
$rs = mysql_query ($sql);
echo mysql_num_rows ($rs). " <br> ";
/**
* Read the data to the array, pay attention to the key and value processing
*/
$code = Array (0=> "GB", big5=>0);

while ($row = Mysql_fetch_array ($rs)) {
$code [Pack ("H4", $row][GBK])] = Pack ("H4", $row [Big5]);
$code [$row][gb2312]] = Pack ("H4", $row [Big5]);
}

Mysql_close ($conn);

function Gb_big5 ($s) {
Global $code;
$v = "";
if ($code [0] = = "Big5")
$code = $arr _flip ($code);
for ($i =0; $i <strlen ($s); $i + +) {
if (Ord ($s [$i]) > 0x7f) {
$p = sprintf ("%02x%02x", $s [$i], $s [$i +1]);
$p = $s [$i]. $s [$i +1];
$ch = $code [$p];
if ($ch = = "")
$ch = $s [$i]. $s [$i +1];
$v. = $ch;
$i + +;
}else
$v. = $s [$i];
}
return $v;
}
Echo ' <meta http-equiv= ' Content-type "content=" text/html; Charset=big5 ">";
Echo Gb_big5 ('
Recently completed the GBK, gb2312, Big5 coding comparison table (including its Hanyu Pinyin) collation
Now in a text file to provide to you, compression package 297k
Where: (all include symbols)
GBK 21791
Big5 15863
gb2312 7478
Note that the data row "," must be under MySQL, or it may be wrong. Some friends get the new version may not, please add.
(2002-10-24)
Interested friends please contact me, email:czjsz_ah@stats.gov.cn

Document Format:
"B6f6", "" "," B6f6 "," 997F "," Hungry "," E ",
"B6f7", "AEA6", "B6f7", "6069", "en", "en",
"B6f8", "a6d3", "B6f8", "800C", "and", "Er|neng",
"B6f9", "A449", "b6f9", "513F", "Son", "Er|ren",
Order: GBK, Big5, gb2312, Unicode, font, pinyin

MySQL Build table code (please change according to the actual situation):
');
?>


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.