Provides a variety of official and user-released code examples. For code reference, you are welcome to exchange and learn PHP Chinese character conversion and first letter, support for audio and keep non-letter content
Thinkphp version 3.2.3
Code has reference this article: http://www.thinkphp1.cn/code/596.html
In the original article, if the first letter is converted to pinyin, non-letter content will be removed.
For example, "Zone B No. 32" is converted into QH. My requirement is to keep non-letter content.
A function is added to the class to retain non-letter content.
Simply put it in Library \ Org \ Util.
Usage
$ Pinyin = new \ Org \ Util \ ChinesePinyin ();
Echo $ Pinyin-> TransformWithTone ("Pinyin with tones ");
Echo $ Pinyin-> TransformWithoutTone ("Pinyin without tones ");
Echo $ Pinyin-> TransformUcwordsOnlyChar ("the first letter only contains the Chinese character BuHanPinYin ");
Echo $ Pinyin-> TransformUcwords ("first letter and other characters such as Zone B 32 ");
Effect:
The code may be incomplete. I hope you can point it out.
Pinyin.zip (66.5 KB download: 85 times)
AD: truly free, domain name + VM + enterprise mailbox = 0 RMB