<?
function getfirstletter($string) {
global $encoding;
if($encoding=='UTF-8'){
$string=string::h
iconv($string,'gbk','utf-8');
}
$dict=array(
'a'=>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'=>0xD1B8,'y'=>0xD4D0,'z'=>0xD7F9,
);
$letter = substr($string, 0, 1);
$letter_ord = ord($letter);
if($letter_ord >= 176 && $letter_ord <= 215){
$num = '0x'.bin2hex(substr($string, 0, 2));
foreach ($dict as $k=>$v){
if($v>=$num)
break;
}
return $k;
}elseif(($letter_ord>64 && $letter_ord<91) || ($letter_ord>96 && $letter_ord<123)){
return $letter;
}elseif($letter>='0' && $letter<='9'){
return $letter;
}else{
return '*';
}
}
echo getfirstletter("你好,我是大山。");
?>