<?php
/*
* @author: zhuyubing@gmail.com
*/
$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 ' =>0xd188,
' y ' =>0xd4d0,
' z ' =>0xd7f9,
);
Take GB2312 the first letter of the string, the principle is GBK Chinese characters are encoded in phonetic order.
Function Get_letter ($input)
{
Global $dict;
$str _1 = substr ($input, 0, 1);
if ($str _1 >= chr (0x81) && $str _1 <= chr (0xFE)) {
$num = Hexdec (Bin2Hex (substr ($input, 0, 2));
foreach ($dict as $k => $v) {
if ($v >= $num)
break;
}
return $k;
}
else{
return $str _1
}
}
echo get_letter (' Middle ');
echo get_letter (' Hua ');
echo get_letter (' man ');
echo get_letter (' people ');
Echo get_letter (' total ');
echo Get_letter (' and ');
Echo get_letter (' state ');
Echo Get_letter (' Long live ');
echo get_letter (' C ');
echo get_letter (' H ');
echo get_letter (' I ');
echo Get_letter (' n ');
Echo Get_letter (' a ');
/**/
?>