PHP提取中文首字母

來源:互聯網
上載者:User

複製代碼 代碼如下:<?
function pykey( $py_key)
{
$pinyin = 65536 + pys($py_key);
if ( 45217 <= $pinyin && $pinyin <= 45252 )
{
$zimu = "A";
return $zimu;
}
if ( 45253 <= $pinyin && $pinyin <= 45760 )
{
$zimu = "B";
return $zimu;
}
if ( 45761 <= $pinyin && $pinyin <= 46317 )
{
$zimu = "C";
return $zimu;
}
if ( 46318 <= $pinyin && $pinyin <= 46825 )
{
$zimu = "D";
return $zimu;
}
if ( 46826 <= $pinyin && $pinyin <= 47009 )
{
$zimu = "E";
return $zimu;
}
if ( 47010 <= $pinyin && $pinyin <= 47296 )
{
$zimu = "F";
return $zimu;
}
if ( 47297 <= $pinyin && $pinyin <= 47613 )
{
$zimu = "G";
return $zimu;
}
if ( 47614 <= $pinyin && $pinyin <= 48118 )
{
$zimu = "H";
return $zimu;
}
if ( 48119 <= $pinyin && $pinyin <= 49061 )
{
$zimu = "J";
return $zimu;
}
if ( 49062 <= $pinyin && $pinyin <= 49323 )
{
$zimu = "K";
return $zimu;
}
if ( 49324 <= $pinyin && $pinyin <= 49895 )
{
$zimu = "L";
return $zimu;
}
if ( 49896 <= $pinyin && $pinyin <= 50370 )
{
$zimu = "M";
return $zimu;
}
if ( 50371 <= $pinyin && $pinyin <= 50613 )
{
$zimu = "N";
return $zimu;
}
if ( 50614 <= $pinyin && $pinyin <= 50621 )
{
$zimu = "O";
return $zimu;
}
if ( 50622 <= $pinyin && $pinyin <= 50905 )
{
$zimu = "P";
return $zimu;
}
if ( 50906 <= $pinyin && $pinyin <= 51386 )
{
$zimu = "Q";
return $zimu;
}
if ( 51387 <= $pinyin && $pinyin <= 51445 )
{
$zimu = "R";
return $zimu;
}
if ( 51446 <= $pinyin && $pinyin <= 52217 )
{
$zimu = "S";
return $zimu;
}
if ( 52218 <= $pinyin && $pinyin <= 52697 )
{
$zimu = "T";
return $zimu;
}
if ( 52698 <= $pinyin && $pinyin <= 52979 )
{
$zimu = "W";
return $zimu;
}
if ( 52980 <= $pinyin && $pinyin <= 53640 )
{
$zimu = "X";
return $zimu;
}
if ( 53689 <= $pinyin && $pinyin <= 54480 )
{
$zimu = "Y";
return $zimu;
}
if ( 54481 <= $pinyin && $pinyin <= 62289 )
{
$zimu = "Z";
return $zimu;
}
$zimu = $py_key;
return $zimu;
}
function pys( $pysa )
{
$pyi = "";
$i= 0;
for ( ; $i < strlen( $pysa ); $i++)
{
$_obfuscate_8w= ord( substr( $pysa,$i,1) );
if ( 160 < $_obfuscate_8w)
{
$_obfuscate_Bw = ord( substr( $pysa, $i++, 1 ) );
$_obfuscate_8w = $_obfuscate_8w * 256 + $_obfuscate_Bw - 65536;
}
$pyi.= $_obfuscate_8w;
}
return $pyi;
}
$letter = pykey("中華人民共和國");
echo $letter;
?>
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.