Generation of Pinyin code table

Source: Internet
Author: User
& Lt ;? Php ** Pinyin code table generation: the startup input method generator is installed with the windowless pinyin input method in the reverse conversion card and saved as the audio file (winpy.txt) for backup. The following code loads the Pinyin code table File (text) into the array $ pymb. The structure is: (pinyin, (Chinese character ...)) the conversion time of the code table is long. convert the data table and save the * $ filename & quot; pymb. t /**
Generation of the Pinyin code table:
Start the input method generator, load the window pinyin input method in the inverse conversion tab, and save it as a text
This file (winpy.txt) is used up.
 
The following code loads the Pinyin code table File (text) into the array $ pymb. The structure is: (pinyin, (Chinese character ...))
Code table conversion takes a long time, which 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, "% 2 s % 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 );
}
?>
Application example: add pinyin to text

/**
Application example: add pinyin to the text. For simplicity, it is assumed that all are 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 = "Pinyin code table generation:
Start the input method generator, load the window pinyin input method in the inverse conversion tab, and save it as a text
This file (winpy.txt) is used up.
 
The following code loads the Pinyin code table File (text) into the array $ pymb. The structure is: (pinyin, (Chinese character ...))
Code table conversion takes a long time, which should be converted and saved separately
";


$ Ar = get_py ($ text );
// PRint_r ($ ar );

Echo"





";For ($ I = 0; $ IEcho" ";}Echo" ";For ($ I = 0; $ IEcho" ";}Echo"
". $ Ar [$ I] [1]."
". $ Ar [$ I] [0]."
";
?>

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.