php 取字符串首字母的方法
0xB0C4,
'b'=>0xB2C0,
'c'=>0xB4ED,
'd'=>0xB6E9,
'e'=>0xB7A1,
'f'=>0xB8C0,
'g'=>0xB9FD,
'h'=>0xBBF6,
'j'=>0xBFA5,
'k'=>0xC0AB,
'l'=>0xC2E7,
'm'=>0xC4C2,
'n'=>0xC5B5,
'o'=>0xC5BD,
'p'=>0xC6D9,
'q'=>0xC8BA,
'r'=>0xC8F5,
's'=>0xCBF9,
't'=>0xCDD9,
'w'=>0xCEF3,
'x'=>0xD188,
'y'=>0xD4D0,
'z'=>0xD7F9,
);
function get_letter($input){
global $dict;
$input = iconv('utf-8', 'gbk', $input);
$str_1 = substr($input, 0, 1);
if ($str_1 >= chr(0x81) && $str_1 <= chr(0xfe)) {
$num = hexdec(bin2hex(substr($input, 0, 2)));
foreach ($dict as $k=>$v){
if($v>=$num)
break;
}
return $k;
} else {
return $str_1;
}
}
echo get_letter('胜利');
?>
这里处理字符串是utf8的情况,如果字符串是gbk,删除$input = iconv('utf-8', 'gbk', $input);就可以了。