zoukankan      html  css  js  c++  java
  • php 获取每个汉字的拼音首字母

     1 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
     2 <?php
     3 function getfirstchar($s0){
     4     $fchar = ord($s0{0});
     5     if($fchar >= ord("A") and $fchar <= ord("z") )return strtoupper($s0{0});
     6     $s1 = $s0;
     7     $s2 = $s1;
     8     //$s1 = iconv("UTF-8","gb2312", $s0);
     9     //$s2 = iconv("gb2312","UTF-8", $s1);
    10     if($s2 == $s0){$s = $s1;}else{$s = $s0;}
    11     $asc = ord($s{0}) * 256 + ord($s{1}) - 65536;
    12     if($asc >= -20319 and $asc <= -20284) return "A";
    13     if($asc >= -20283 and $asc <= -19776) return "B";
    14     if($asc >= -19775 and $asc <= -19219) return "C";
    15     if($asc >= -19218 and $asc <= -18711) return "D";
    16     if($asc >= -18710 and $asc <= -18527) return "E";
    17     if($asc >= -18526 and $asc <= -18240) return "F";
    18     if($asc >= -18239 and $asc <= -17923) return "G";
    19     if($asc >= -17922 and $asc <= -17418) return "I";
    20     if($asc >= -17417 and $asc <= -16475) return "J";
    21     if($asc >= -16474 and $asc <= -16213) return "K";
    22     if($asc >= -16212 and $asc <= -15641) return "L";
    23     if($asc >= -15640 and $asc <= -15166) return "M";
    24     if($asc >= -15165 and $asc <= -14923) return "N";
    25     if($asc >= -14922 and $asc <= -14915) return "O";
    26     if($asc >= -14914 and $asc <= -14631) return "P";
    27     if($asc >= -14630 and $asc <= -14150) return "Q";
    28     if($asc >= -14149 and $asc <= -14091) return "R";
    29     if($asc >= -14090 and $asc <= -13319) return "S";
    30     if($asc >= -13318 and $asc <= -12839) return "T";
    31     if($asc >= -12838 and $asc <= -12557) return "W";
    32     if($asc >= -12556 and $asc <= -11848) return "X";
    33     if($asc >= -11847 and $asc <= -11056) return "Y";
    34     if($asc >= -11055 and $asc <= -10247) return "Z";
    35     return null;
    36 }
    37 
    38 
    39 function pinyin1($zh){
    40     $ret = "";
    41     $s1 = iconv("UTF-8","gb2312", $zh);
    42     $s2 = iconv("gb2312","UTF-8", $s1);
    43     if($s2 == $zh){$zh = $s1;}
    44     for($i = 0; $i < strlen($zh); $i++){
    45         $s1 = substr($zh,$i,1);
    46         $p = ord($s1);
    47         if($p > 160){
    48             $s2 = substr($zh,$i++,2);
    49             $ret .= getfirstchar($s2);
    50         }else{
    51             $ret .= $s1;
    52         }
    53     }
    54     return $ret;
    55 }
    56 echo "测试123aaa<br/>";
    57 echo pinyin1('测试123aaa');
    58 
    59 ?>
    View Code
  • 相关阅读:
    多态
    163VIP邮箱哪个好?为什么要使用邮箱客户端?
    163邮箱的格式什么样的?常见的电子邮箱品牌有哪些?
    申请企业邮箱需要准备什么材料?外贸邮箱怎么注册?
    《10秒挑战》h5游戏案例分析
    H5反应类爆款游戏分享
    企业邮箱多少钱,哪家企业邮箱更具性价比?
    注册申请企业邮箱,哪家最优惠 #万元礼包来袭#
    购买一个163VIP邮箱,3位超短靓号更惊喜~
    小程序对H5游戏的技术分析
  • 原文地址:https://www.cnblogs.com/zheart/p/7239329.html
Copyright © 2011-2022 走看看