您好,登錄后才能下訂單哦!
本篇文章給大家分享的是有關使用php怎么獲取中文字符串的首字母,小編覺得挺實用的,因此分享給大家學習,希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。
復制代碼 代碼如下:
function chineseFirst($str)
{
$str= iconv("UTF-8","gb2312", $str); //如果程序是gbk的,此行就要注釋掉
//判斷字符串是否全都是中文
if (preg_match("/^[\x7f-\xff]/", $str))
{
$fchar=ord($str{0});
if($fchar>=ord("A") and $fchar<=ord("z") )return strtoupper($str{0});
$a = $str;
$val=ord($a{0})*256+ord($a{1})-65536;
if($val>=-20319 and $val<=-20284)return "A";
if($val>=-20283 and $val<=-19776)return "B";
if($val>=-19775 and $val<=-19219)return "C";
if($val>=-19218 and $val<=-18711)return "D";
if($val>=-18710 and $val<=-18527)return "E";
if($val>=-18526 and $val<=-18240)return "F";
if($val>=-18239 and $val<=-17923)return "G";
if($val>=-17922 and $val<=-17418)return "H";
if($val>=-17417 and $val<=-16475)return "J";
if($val>=-16474 and $val<=-16213)return "K";
if($val>=-16212 and $val<=-15641)return "L";
if($val>=-15640 and $val<=-15166)return "M";
if($val>=-15165 and $val<=-14923)return "N";
if($val>=-14922 and $val<=-14915)return "O";
if($val>=-14914 and $val<=-14631)return "P";
if($val>=-14630 and $val<=-14150)return "Q";
if($val>=-14149 and $val<=-14091)return "R";
if($val>=-14090 and $val<=-13319)return "S";
if($val>=-13318 and $val<=-12839)return "T";
if($val>=-12838 and $val<=-12557)return "W";
if($val>=-12556 and $val<=-11848)return "X";
if($val>=-11847 and $val<=-11056)return "Y";
if($val>=-11055 and $val<=-10247)return "Z";
} else
{
return false;
}
}
以上就是使用php怎么獲取中文字符串的首字母,小編相信有部分知識點可能是我們日常工作會見到或用到的。希望你能通過這篇文章學到更多知識。更多詳情敬請關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。