In our last class we introduced php example development of a highly efficient RMB amount conversion program, so in our reality we often see such instructions, ranked in no particular order, Sort by initials. This is the sorting method used by most Chinese people. So how to operate it in php program?
The first step is to download the PHP class library for converting Chinese characters to Pinyin to get the initial letters that we need for this course: http://www.php.cn/xiazai/leiku/742
The 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 "codepy.php"; //引入文件类 $pinyin = new Pinyin(); //实例化此类 //输出结果 echo $pinyin->getFirstChar("安徽合肥")."<br/>"; echo $pinyin->getPinyin("php中文网")."<br/>"; echo $pinyin->getPinyin("中文网")."<br/>"; echo $pinyin->getFirstChar("www.php.cn")."<br/>"; echo $pinyin->getFirstChar("PHP.CN")."<br/>"; ?>
Run this file and the result will be as follows:
The above is the detailed content of Example sharing of converting Chinese characters to Pinyin to get the first letter in PHP. For more information, please follow other related articles on the PHP Chinese website!