Home > Backend Development > PHP Tutorial > Another quick one_PHP tutorial

Another quick one_PHP tutorial

WBOY
Release: 2016-07-13 16:54:07
Original
985 people have browsed it

/**
Generation of Pinyin code table:
Start the input method generator, load the pinyin input method of window in the reverse conversion tab and save it as a file
This file (winpy.txt) is for later use.

The following code loads the Pinyin code table file (text) into the array $pymb. The structure is: (Pinyin, (Chinese characters...))
The code table conversion takes a long time and should be converted Save it later
*/
$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 >= "啊" && 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. For simplicity, assume all in Chinese
*/
function get_py($text) {
    global $pymb;
    $i = 0;
    $n = strlen($text);
    $ar = array();

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/631820.htmlTechArticle?php /** 拼音码表的生成: 启动输入法生成器在逆转换选项卡中装入window的拼音输入法并将其保存为文 本文件(winpy.txt)备用。 下面的代码将拼...
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