PHP   发布时间:2022-04-09  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了PHP实现将汉字转换为拼音及获取词语首字母的方法大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

本文实例讲述了PHP实现将汉字转换为拼音及获取词语首字母的方法分享给大家供大家参,具体如下:

最近要开发将汉字转换为拼音和得到首字的功能记录下来哈子:呵呵~

= '5.0') ? array_combine ( $_TDataKey,$_TDataValue ) : $this->_Array_Combine( $_TDataKey,$_TDataValue );
    arsort ( $data );
    reset ( $data );
    $str = $this->safe_encoding ( $str );
    $_Res = '';
    for($i = 0; $i < strlen="" (="" $str="" );="" $i="" ++)="" {="" $_p="ord" (="" substr="" (="" $str,$i,1="" )="" );="" if="" ($_p=""> 160) {
        $_Q = ord ( substr ( $str,++ $i,1 ) );
        $_P = $_P * 256 + $_Q - 65536;
      }
      $_Res .= $this->_Pinyin ( $_P,$data ).$pix;
    }
    return preg_replace ( "/[^a-z0-9".$pix."]*/",'',$_Res );
  }
  private function _Pinyin($_Num,$_Data) {
    if ($_Num > 0 && $_Num < 160)="" return="" chr="" (="" $_num="" );="" elseif="" ($_num="">< -="" 20319="" ||="" $_num=""> - 10247)
      return '';
    else {
      foreach ( $_Data as $k => $v ) {
        if ($v <= $_num)="" break;="" }="" return="" $k;="" }="" }="" public="" function="" getfirstchar($str='' ){="" if(="" !$str="" )="" return="" null;="" $fchar="ord($str{0});" if($fchar="">=ord("A") and $fchar<=ord("z") )return="" strtoupper($str{0});="" $s="$this-">safe_encoding($str);
    $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;="" }="" function="" safe_encoding($string)="" {="" $encoding="UTF-8" ;="" for($i=""><128) continue;="" if((ord($string{$i})&224)="=224)" {="" 第一个字节判断通过="" $char="$string{++$i};" if((ord($char)&128)="=128)" {="" 第二个字节判断通过="" $char="$string{++$i};" if((ord($char)&128)="=128)" {="" $encoding="UTF-8" ;="" break;="" }="" }="" }="" if((ord($string{$i})&192)="=192)" {="" 第一个字节判断通过="" $char="$string{++$i};" if((ord($char)&128)="=128)" {="" 第二个字节判断通过="" $encoding="GB2312" ;="" break;="" }="" }="" }="" if(strtoupper($encoding)="=strtoupper($this-">_outEncoding))
      return $String;
    else
      return iconv($encoding,$this->_outEncoding,$String);
  }
  private function _Array_Combine($_Arr1,$_Arr2){
    for($i = 0; $i < count="" (="" $_arr1="" );="" $i="" ++)="" $_res="" [$_arr1="" [$i]]="$_Arr2" [$i];="" return="" $_res;="" }="" }="">@H_772_47@

大佬总结

以上是大佬教程为你收集整理的PHP实现将汉字转换为拼音及获取词语首字母的方法全部内容,希望文章能够帮你解决PHP实现将汉字转换为拼音及获取词语首字母的方法所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。