溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

利用PHP怎么對(duì)中英文的首字母進(jìn)行獲取

發(fā)布時(shí)間:2020-12-24 15:19:59 來源:億速云 閱讀:152 作者:Leah 欄目:開發(fā)技術(shù)

這篇文章給大家介紹利用PHP怎么對(duì)中英文的首字母進(jìn)行獲取,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對(duì)大家能有所幫助。

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; 
        } 
  }

關(guān)于利用PHP怎么對(duì)中英文的首字母進(jìn)行獲取就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI