Home  >  Article  >  Backend Development  >  Example sharing of converting Chinese characters to Pinyin to get the first letter in PHP

Example sharing of converting Chinese characters to Pinyin to get the first letter in PHP

黄舟
黄舟Original
2017-08-16 13:52:251996browse

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:

Example sharing of converting Chinese characters to Pinyin to get the first letter in PHP

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn