$piny = Array (
' A ' =>-20319,
' Ai ' =>-20317,
' An ' =>-20304,
' Ang ' =>-20295
);
Echo getchinesespells (' China web first station www.111cn.net ');
Take all pinyin of Chinese characters
function Getchinesespells ($chinese, $delimiter = ', $first =0)
{
$result = Array ();
for ($i =0; $i <strlen ($chinese); $i + +) {
$p = Ord (substr ($chinese, $i, 1));
if ($p >160) {
$q = Ord (substr ($chinese, + + $i, 1));
$p = $p *256 + $q-65536;
}
$result [] = Getchinesespell ($p);
if ($first) {
return $result [0];
}
}
Return implode ($delimiter, $result);
}
To take a Chinese character code corresponding to the pinyin
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, take the first pinyin of Chinese characters
function Getfirstspell ($chinese, $length = 0) {
$spell =getchinesespells ($chinese, ', 1);
if ($length) {
$spell = substr ($spell, 0, $length);
}
return $spell;
}
/*
*/