php 漢語轉拼音函數

來源:互聯網
上載者:User
php 中文轉拼音函數
剛在部落格園發現一個很好用的函數,可以將中文轉成拼音,轉載一下
160) {                         $_Q = ord(substr($_String, ++$i, 1)); $_P = $_P*256 + $_Q - 65536;                }                 $_Res .= _Pinyin($_P, $_Data);         }         return preg_replace("/[^a-z0-9]*/", '', $_Res); } 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;         } }function _U2_Utf8_Gb($_C){         $_String = '';         if($_C < 0x80){                $_String .= $_C;        }elseif($_C < 0x800) {                 $_String .= chr(0xC0 | $_C>>6);                 $_String .= chr(0x80 | $_C & 0x3F);         }elseif($_C < 0x10000){                 $_String .= chr(0xE0 | $_C>>12);                 $_String .= chr(0x80 | $_C>>6 & 0x3F);                 $_String .= chr(0x80 | $_C & 0x3F);         }elseif($_C < 0x200000) {                 $_String .= chr(0xF0 | $_C>>18);                 $_String .= chr(0x80 | $_C>>12 & 0x3F);                 $_String .= chr(0x80 | $_C>>6 & 0x3F);                 $_String .= chr(0x80 | $_C & 0x3F);         }         return iconv('UTF-8', 'GB2312', $_String); }//測試echo Pinyin('中文字','gb2312'); //第二個參數“1”可隨意設定即為utf8編碼?>
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.