- $ Str = "this is a test procedure 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 Chinese character
- $ 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 sorting
- Array (45217,45252), //
- Array (45253,45760), // B
- Array (45761,46317), // C
- Array (46318,46825), // D
- Array (46826,47009), // E
- Array (, 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 (5th, 54th), // Y
- Array (54481,55289), // Z
- );
- $ Char_index = 65;
- Foreach ($ limit as $ k =>v v ){
- If ($ num> = $ v [0] & $ num <= $ v [1]) {
- $ Char_index + = $ k;
- Return $ char_index;
- }
- }
- Return-1;
- }
|