使用PHP怎么獲取漢字的首字母、?針對這個問題,這篇文章詳細介紹了相對應(yīng)的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。

<?php
function getFirstCharter($str)
{
if (empty($str)) {
return '';
}
$fchar = ord($str{0});
if ($fchar >= ord('A') && $fchar <= ord('z'))
return strtoupper($str{0});
$s1 = iconv('UTF-8', 'gb2312', $str);
$s2 = iconv('gb2312', 'UTF-8', $s1);
$s = $s2 == $str ? $s1 : $str;
$asc = ord($s{0}) * 256 + ord($s{1}) - 65536;
if ($asc >= -20319 && $asc <= -20284)
return 'A';
if ($asc >= -20283 && $asc <= -19776)
return 'B';
if ($asc >= -19775 && $asc <= -19219)
return 'C';
if ($asc >= -19218 && $asc <= -18711)
return 'D';
if ($asc >= -18710 && $asc <= -18527)
return 'E';
if ($asc >= -18526 && $asc <= -18240)
return 'F';
if ($asc >= -18239 && $asc <= -17923)
return 'G';
if ($asc >= -17922 && $asc <= -17418)
return 'H';
if ($asc >= -17417 && $asc <= -16475)
return 'J';
if ($asc >= -16474 && $asc <= -16213)
return 'K';
if ($asc >= -16212 && $asc <= -15641)
return 'L';
if ($asc >= -15640 && $asc <= -15166)
return 'M';
if ($asc >= -15165 && $asc <= -14923)
return 'N';
if ($asc >= -14922 && $asc <= -14915)
return 'O';
if ($asc >= -14914 && $asc <= -14631)
return 'P';
if ($asc >= -14630 && $asc <= -14150)
return 'Q';
if ($asc >= -14149 && $asc <= -14091)
return 'R';
if ($asc >= -14090 && $asc <= -13319)
return 'S';
if ($asc >= -13318 && $asc <= -12839)
return 'T';
if ($asc >= -12838 && $asc <= -12557)
return 'W';
if ($asc >= -12556 && $asc <= -11848)
return 'X';
if ($asc >= -11847 && $asc <= -11056)
return 'Y';
if ($asc >= -11055 && $asc <= -10247)
return 'Z';
return null;
}
$firstChar = getFirstCharter('創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司,');
print_r($firstChar);//輸出:J
?>關(guān)于使用PHP怎么獲取漢字的首字母、問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關(guān)知識。
網(wǎng)站名稱:使用PHP怎么獲取漢字的首字母、-創(chuàng)新互聯(lián)
網(wǎng)站路徑:http://www.chinadenli.net/article34/dpshpe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導航、域名注冊、網(wǎng)站設(shè)計公司、響應(yīng)式網(wǎng)站、網(wǎng)站制作、網(wǎng)站收錄
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容