php程序如何把中文字符转换为拼音(4)
{
$string .= chr(0xC0 | $char>>6);
$string .= chr(0x80 | $char & 0x3F);
}elseif($char < 0x10000){
$string .= chr(0xE0 | $char>>12);
$string .= chr(0x80 | $char>>6 & 0x3F);
$string .= chr(0x80 | $char & 0x3F);
} elseif($char < 0x200000) {
$string .= chr(0xF0 | $char>>18);
$string .= chr(0x80 | $char>>12 & 0x3F);
$string .= chr(0x80 | $char>>6 & 0x3F);
$string .= chr(0x80 | $char & 0x3F);
}
return iconv('UTF-8', 'GB2312//IGNORE', $string);
}
/**
* 比较数组
* @param $arr1 数组1
* @param $arr2 数组2
*/
public function arrayCombine($arr1, $arr2)
{
for($i=0; $i<count($arr1); $i++) $res[$arr1[$i]] = $arr2[$i];
return $res;
}
/**
*获得汉字的拼音首字母
* @param $str 字符串
*/
public function getInitial($str,$charset) {
if($charset=="UTF-8")$str=$this->utf82GB2312($str);
$asc = ord(substr($str, 0, 1));
if ($asc < 160) {//非中文
if ($asc >= 48 && $asc <= 57) {
return chr($asc); //数字
} elseif ($asc >= 65 && $asc <= 90) {
return chr($asc); // A--Z
相关新闻>>
- 发表评论
-
- 最新评论 更多>>