In our previous courses, we have introduced to you php development examples that support the conversion of Chinese characters into pinyin for rare characters. I believe everyone has a certain understanding of this, so today we will introduce to you, php to obtain Chinese The first letter of Pinyin, English string: return unchanged (including numbers) eg. abc123 => abc123, Chinese string: return the first character of Pinyin eg. Test string => CSZFC, Chinese and English mixed string: return the first character of Pinyin Characters and English eg. IiIj => WIWJ!
First step, first download the php we need to use for this course to obtain the Chinese Pinyin initial letter tool library: http://www.php.cn/xiazai/leiku/417
Second step, after the download is completed, find the php class file we need, unzip it to our local directory, and create a new php file!
The third step, after completion, we need to call this class in the new php file and instantiate the class:
<?php include_once "pingyin.php"; //引入类文件 $py = new str2PY(); //实例化 echo $py->getInitials('中')."<br>"; //获取首字母 echo $py->getFirstString('fgh')."<br>"; //F echo $py->getFirstString("中文网"); //Z ?>
Run this file and get the result as shown below:
The above is the detailed content of Analysis of development examples of using PHP to obtain the first letter of Chinese (string) pinyin. For more information, please follow other related articles on the PHP Chinese website!