PHP kanji to Pinyin _php tutorial

Source: Internet
Author: User
PHP Kanji to Pinyin

PHP Functions (modified by the Spgetpinyin function of Dedecms (dedecms/include/inc/inc_fun_funadmin.php), dedecms dictionaries are not quite complete):

 PhpfunctionPinyin$str,$ishead) {        Static $pinyins=Array(); $restr= ''; $str=Trim($str); $slen=strlen($str); if($slen< 2) {            return $str; }        if(Count($pinyins) = = 0) {            $fp=fopen(' Pinyin.dic ', ' R ');  while(!feof($fp)) {                $line=Trim(fgets($fp)); $a 2=Explode('`',$line); isset($a 2[1]) &&$pinyins[$a 2[0]] =$a 2[1]; }            fclose($fp); }                 for($i= 0;$i<$slen;$i++) {            if(Ord($str[$i]) >0x80) {                $c=$str[$i].$str[$i+1]; $i++; if(isset($pinyins[$c])) {                    $restr.= ($ishead==0)?$pinyins[$c]:$pinyins[$c][0]; }Else {                    $restr.= "_"; }            }Else if(Preg_match("/[a-z0-9]/i",$str[$i]) ) {                $restr.=$str[$i]; }            Else {                $restr.= "_"; }        }        return $restr; }        //Test    EchoPinyin (' Shu Jia insulation film ', 1), '
'; EchoPinyin (' Shu Jia insulation film ', 0), '
'; EchoPinyin (' Parrot ', 1), '
'; EchoPinyin (' parrot ', 0), '
'; EchoPinyin (' Sleeping fort/Innovation/myside Mattress ', 1), '
'; EchoPinyin (' Sleeping fort/Innovation/myside Mattress ', 0), '
'; /*results: srjgrm shurejiageremo yw yingwu mzb_ynws_mysidecd mianzhibao_yinuoweishen_mysidechuangdian*/?>

The included dictionaries are attached: pinyin.rar/pinyin.dic (GBK)

Download Address: Http://files.cnblogs.com/luoyunshu/pinyin.rar

Reference:

http://www.oschina.net/code/snippet_862384_25415

http://www.bkjia.com/PHPjc/822275.html www.bkjia.com true http://www.bkjia.com/PHPjc/822275.html techarticle PHP kanji to pinyin php function (modified by DEDECMS (dedecms/include/inc/inc_fun_funadmin.php) spgetpinyin function, Dedecms dictionary is not quite complete): PHP function Pinyin ($str, $is ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.