PHP は中国語と英語のイニシャルを抽出するメソッドを実装します

墨辰丷
リリース: 2023-03-31 10:56:01
オリジナル
1441 人が閲覧しました

この記事では、PHP を使用して中国語と英語の文字の最初の文字を抽出する簡単な方法と例を紹介します。必要な場合は非常に便利です。

PHP は、中国語と英語を頭文字に従って取得する実装を実装します

/** 
  * 
  */ 
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; 
        } 
  }
ログイン後にコピー

概要: 上記がこの記事の全内容です。皆さんの学習に役立つことを願っています。

関連する推奨事項:

php で JSON エンコード変換を実装するメソッド

php ではチェーンを使用します。呼び出し方法と連続呼び出しで関数を使用する方法

php数値と数値動作確認コード

以上がPHP は中国語と英語のイニシャルを抽出するメソッドを実装しますの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

関連ラベル:
php
ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
最新の問題
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!