您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php获取中文字符串的首字符拼音字母

2024/5/7 6:09:02发布21次查看
$str=这是一个测试程序1; echo getfirstcharcode($str); function getfirstcharcode($str){ $str= iconv(utf-8,gb2312, $str); $targetchar='*'; $i=0; while($i='b0'){ //汉字的开始 $t=getletter(hexdec(bin2hex(substr($str,$i,2)))); $targetchar=$t==-1 ? '*' : $t ; //printf(%c,$t==-1 ? '*' : $t ); break; //$i+=2; } else{ $targetchar=substr($str,$i,1); break; //printf(%s,substr($str,$i,1)); //$i++; } } if(is_numeric($targetchar)){ return chr($targetchar); } else{ return $targetchar; } } function getletter($num){ $limit=array( //gb2312 拼音排序 array(45217,45252), //a array(45253,45760), //b array(45761,46317), //c array(46318,46825), //d array(46826,47009), //e array(47010,47296), //f array(47297,47613), //g array(47614,48118), //h array(0,0), //i array(48119,49061), //j array(49062,49323), //k array(49324,49895), //l array(49896,50370), //m array(50371,50613), //n array(50614,50621), //o array(50622,50905), //p array(50906,51386), //q array(51387,51445), //r array(51446,52217), //s array(52218,52697), //t array(0,0), //u array(0,0), //v array(52698,52979), //w array(52980,53688), //x array(53689,54480), //y array(54481,55289), //z ); $char_index=65; foreach($limit as $k=>$v){ if($num>=$v[0] && $num<=$v[1]){ $char_index+=$k; return $char_index; } } return -1; }
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product