The above three functions correspond to the Chinese character code, which is equivalent to the conversion to pinyin. Our example is simple. We only use the example code for converting Chinese characters starting with a to pinyin. The above three functions correspond to the Chinese character code, which is equivalent to the conversion to pinyin. Our example is simple. We only use the example code for converting Chinese characters starting with a to pinyin.
Script ec (2); script
$ Piny = array (
& Apos; a & apos; = & apos;-20319 & apos,
'Ai' =>-20317,
'Any' =>-20304,
'Ang '=>-20295
);
Echo getChineseSpells ('first Chinese WEB Station www.111cn.net ');
// Retrieve all Chinese Characters in pinyin
Function getChineseSpells ($ chinese, $ delimiter = '', $ first = 0)
{
$ Result = array ();
For ($ I = 0; $ I $ P = ord (substr ($ chinese, $ I, 1 ));
If ($ p & gt; 160 ){
$ Q = ord (substr ($ chinese, ++ $ I, 1 ));
$ P = $ p * 256 + $ q-65536;
}
$ Result [] = getChineseSpell ($ p );
If ($ first ){
Return $ result [0];
}
}
Return implode ($ delimiter, $ result );
}
// Obtain the pinyin corresponding to a Chinese character code
Function getChineseSpell ($ num, $ blank = ''){
If ($ num> 0 & $ num <160 ){
Return chr ($ num );
} Elseif ($ num <-20319 | $ num>-10247 ){
Return $ blank;
} Else {
Foreach (chineseSpellList as $ spell => $ code ){
If ($ code> $ num) break;
$ Result = $ spell;
}
Return $ result;
}
}
// Function, which is the first Chinese pinyin
Function getFirstSpell ($ chinese, $ length = 0 ){
$ Spell = getChineseSpells ($ chinese, '', 1 );
If ($ length ){
$ Spell = substr ($ spell, 0, $ length );
}
Return $ spell;
}
/*
*/