PHP實(shí)現(xiàn)獲取中英文首字母
更新時間:2015年06月19日 11:00:36 投稿:hebedich
本文給大家分享的是使用php簡單實(shí)現(xiàn)的提取中英文字符的首字母的方法和示例,十分的使用,有需要的小伙伴可以參考下。
PHP實(shí)現(xiàn)獲取中英文按照首字母
/**
*
*/
function getfirstchar($s0){
if($s0[0]=='I' || $s[0]=='i'){
return "I";
}elseif($s0[0]=='U' || $s[0]=='u'){
return 'U';
}elseif($s0[0]=='V' || $s[0]=='v'){
return 'V';
}else{
$fchar = ord($s0{0});
if($fchar >= ord("A") and $fchar <= ord("z") )return strtoupper($s0{0});
$s1 = iconv("UTF-8","gb2312", $s0);
$s2 = iconv("gb2312","UTF-8", $s1);
if($s2 == $s0){$s = $s1;}else{$s = $s0;}
$asc = ord($s{0}) * 256 + ord($s{1}) - 65536;
if($asc >= -20319 and $asc <= -20284) return "A";
if($asc >= -20283 and $asc <= -19776) return "B";
if($asc >= -19775 and $asc <= -19219) return "C";
if($asc >= -19218 and $asc <= -18711) return "D";
if($asc >= -18710 and $asc <= -18527) return "E";
if($asc >= -18526 and $asc <= -18240) return "F";
if($asc >= -18239 and $asc <= -17923) return "G";
if($asc >= -17922 and $asc <= -17418) return "H";
if($asc >= -17417 and $asc <= -16475) return "J";
if($asc >= -16474 and $asc <= -16213) return "K";
if($asc >= -16212 and $asc <= -15641) return "L";
if($asc >= -15640 and $asc <= -15166) return "M";
if($asc >= -15165 and $asc <= -14923) return "N";
if($asc >= -14922 and $asc <= -14915) return "O";
if($asc >= -14914 and $asc <= -14631) return "P";
if($asc >= -14630 and $asc <= -14150) return "Q";
if($asc >= -14149 and $asc <= -14091) return "R";
if($asc >= -14090 and $asc <= -13319) return "S";
if($asc >= -13318 and $asc <= -12839) return "T";
if($asc >= -12838 and $asc <= -12557) return "W";
if($asc >= -12556 and $asc <= -11848) return "X";
if($asc >= -11847 and $asc <= -11056) return "Y";
if($asc >= -11055 and $asc <= -10247) return "Z";
return null;
}
}
以上所述就是本文的全部內(nèi)容了,希望大家能夠喜歡。
相關(guān)文章
ThinkPHP權(quán)限認(rèn)證Auth實(shí)例詳解
這篇文章主要介紹了ThinkPHP權(quán)限認(rèn)證Auth實(shí)例,需要的朋友可以參考下2014-07-07
有道搜索和IP138的IP的API接口(PHP應(yīng)用)
原理就是通過php模擬瀏覽器獲取ip地址歸屬地,需要的朋友可以參考下2012-11-11
將PHP程序中返回的JSON格式數(shù)據(jù)用gzip壓縮輸出的方法
這篇文章主要介紹了將PHP中返回的JSON格式數(shù)據(jù)用gzip壓縮輸出的方法,文中示例環(huán)境為Linux系統(tǒng)與Apache服務(wù)器,需要的朋友可以參考下2016-03-03
微信公眾號實(shí)現(xiàn)掃碼獲取微信用戶信息(網(wǎng)頁授權(quán))
剛開始接觸微信的時候一頭霧水,領(lǐng)導(dǎo)想要一個掃碼獲取微信用戶信息的功能,接下來通過本文給大家分享微信公眾號實(shí)現(xiàn)掃碼獲取微信用戶信息(網(wǎng)頁授權(quán)),需要的朋友可以參考下2019-04-04
ThinkPHP采用原生query實(shí)現(xiàn)關(guān)聯(lián)查詢left join實(shí)例
這篇文章主要介紹了ThinkPHP采用原生query實(shí)現(xiàn)關(guān)聯(lián)查詢left join的方法,實(shí)例展示了ThinkPHP中query方法的使用技巧,需要的朋友可以參考下2014-12-12
laravel-admin 實(shí)現(xiàn)在指定的相冊下添加照片
今天小編就為大家分享一篇laravel-admin 實(shí)現(xiàn)在指定的相冊下添加照片,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-10-10

