- $str="これは一测试程序1";
-
- echo getFirstCharCode($str);
-
-
- function getFirstCharCode($str){
- $str= iconv("UTF-8","gb2312" , $str);
- $targetChar='*';
- $i=0;
-
- while($i $tmp=bin2hex(substr($str,$i,1)) ;
- if($tmp>='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
- 配列(47010,47296), //F
- 配列(47297,47613), //G
- 配列(47614,48118), //H
- 配列(0,0), //I
- 配列(48119,49061), //J
- 配列(49062,49323), //K
- 配列(49324,49895), //L
- 配列(49896,50370), //M
- 配列(50371,50613) ), //N
- 配列(50614,50621), //O
- 配列(50622,50905), //P
- 配列(50906,51386), //Q
- 配列(51387,51445), //R
- array(51446,52217), //S
- array(52218,52697), //T
- array(0,0), //U
- array(0,0), //V
- array(52698,52979) , //W
- 配列(52980,53688), //X
- 配列(53689,54480), //Y
- 配列(54481,55289), //Z
- );
- $char_index=65;
- foreach($ $k=>$v){
- if($num>=$v[0] && $num $char_index+=$k;
- return $char_index;
- }
- }
- return -1;
- }
复制代
|