- $str = "This is a test program 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 ') {//start of Kanji
- $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 pinyin sort
- 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;
- }
Copy Code
|