Kanji to Pinyin

Source: Internet
Author: User

    /*--------------------------* Kanji to Pinyin * $str the string to convert * $split if you want to split the display * $isfirst return the first letter
* _cnfonts.php (a total of 25961 characters, including 20902 basic words + 5059 uncommon words)
* Http://files.cnblogs.com/files/helin/_cnfonts.zip-*------------------------*/ functionPinYin ($str,$split=true,$isfirst=false){ Static $pinyins; if(!isset($pinyins)){ include_once' _cnfonts.php ';//$_cnfonts= ' ... '; $a 1=Explode(' | ',$_cnfonts); $pinyins=Array(); foreach($a 1 as $v) { $a 2=Explode(‘:‘,$v); $pinyins[$a 2[0]] =$a 2[1]; } } $py= ' '; $str=Trim($str); $str _arr=Preg_split('/(? <!^) (?! $)/U ',$str ); foreach($str _arr as $code){ if(isset($pinyins[$code])) { $py.= ($split&&$py? ‘ ‘ : ‘‘ ). ($isfirst?Strtoupper($pinyins[$code][0]):$pinyins[$code]); }Else{ $py.=$code; } } return $py; }

  

Kanji to Pinyin

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.