/**
Phonetic Code table Generation:
Start the Input Method Builder in the Invert tab, mount the phonetic Input Method for window and save it as a text
This document (Winpy.txt) is reserved.
The following code loads the Phonetic Code table file (text) into the array $pymb, with the structure: (Pinyin, (Kanji ...))
The Code table conversion time is longer, should be converted and saved 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). "");
Fclose ($FP);
}
?>
Application example, add Pinyin to text
/**
Use examples to add pinyin to the text. For the sake of simplification, it is assumed that all Chinese
*/
function Get_py ($text) {
Global $PYMB;
$i = 0;
$n = strlen ($text);
$ar = Array ();
http://www.bkjia.com/PHPjc/631820.html www.bkjia.com true http://www.bkjia.com/PHPjc/631820.html techarticle ? PHP/** Phonetic Code table generation: Start the Input Method Builder in the Inverse Conversion tab, mount the Phonetic IME for window and save it as a text file (winpy.txt) alternate. The following code will spell ...