|
★☆☆☆☆☆☆☆☆☆ |
积分:285 |
发帖:317 |
登录:2024/3/26 |
注册:2006/6/28 |
|
(1楼)【原创】PHP获取汉字拼音的首字母
function getFirstPY($str) {
$ost = array(65, -35, 45252);
$dic = array(0,508,1065,1573,1757,2044,2361,2866,2866,3809,4071,4643,5118,5361,5369,5653,6134,6193,6965,7445,7445,7445,7727,8436,9228,10037);
$gbk = iconv("UTF-8", "GBK", $str);
$asc = ord($gbk[0]) * 256 + ord($gbk[1]) - $ost[2];
// 不存在的可能不是汉字,直接当作字母返回第一个
if($asc < $ost[1]) return $str[0];
foreach($dic as $i => $n) { if($asc <= $n) return chr($ost[0] + $i); }
return $str[0];
}
|