The generation of Phonetic code table

Source: Internet
Author: User
Tags array count ord
<?php
/**
Generation of Phonetic Code table:
Start the Input method Builder to load the window's phonetic input method on the Reverse Conversion tab and save it as a text
This document (Winpy.txt) is standby.

The following code loads the Phonetic Code table file (text) into the array $pymb: (Pinyin, (Chinese characters ...))
Code table conversion Time is longer, should be converted to save separately
*/
$filename = "Pymb.txt";
if (file_exists ($filename)) {
$fp = fopen ($filename, "R");
$PYMB = Unserialize (Fread ($fp, FileSize ($filename));
Fclose ($FP);
}else {
$filename = "Winpy.txt";
$fp = fopen ($filename, "R");
$old = "";
$ar = Array ();
$PYMB = Array ();
while (! feof ($fp)) {
$buffer = fgets ($fp, 128);
SSCANF ($buffer, "%2s%s", $ch, $py);
if ($ch >= "Ah" && Ord ($py) < 128) {
$PYMB [$ch] = $py;
}
}
Fclose ($FP);
$fp = fopen ("Pymb.txt", "w");
Fwrite ($FP, Serialize ($PYMB). " \ n ");
Fclose ($FP);
}
?>
Use examples to add Pinyin to text <br>
?
/**
Use examples to add Pinyin to text. For simplicity, the assumption is all Chinese
*/

function Get_py ($text) {
Global $PYMB;
$i = 0;
$n = strlen ($text);
$ar = Array ();
while ($i < $n) {
$ch = $text [$i + +];
$py = "";
if (ord ($ch) > 128) {
$ch. = $text [$i + +];
$py = $PYMB [$ch];
}
$ar [] = Array ($ch, $py);
}
return $ar;
}

$text = "Generation of phonetic Code table:
Start the Input method Builder to load the window's phonetic input method on the Reverse Conversion tab and save it as a text
This document (Winpy.txt) is standby.

The following code loads the Phonetic Code table file (text) into the array $pymb: (Pinyin, (Chinese characters ...))
Code table conversion Time is longer, should be converted to save separately
";


$ar = Get_py ($text);
Print_r ($ar);

echo "<table><tr align=center>";
for ($i =0; $i <count ($ar); $i + +) {
echo "<td>" $ar [$i][1]. " </td> ";
}
echo "</tr><tr align=center>";
for ($i =0; $i <count ($ar); $i + +) {
echo "<td>" $ar [$i][0]. " </td> ";
}
echo "</tr></table>";
?>



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.