search
HomePHP LibrariesOther librariesPHP library for converting Chinese characters into pinyin
PHP library for converting Chinese characters into pinyin
<?php
/**
 * Created by PhpStorm.
 * User: jifei
 * Date: 15/6/25
 * Time: 下午2:26
 */
class Pinyin
{
    //中文字符串
    private static $string = '';
    //拼音
    private static $pinyin = '';
    private static $encoding = 'UTF-8';
    //短拼音
    private static $short_pinyin = '';
    //单个汉字拼音的字典
    private static $dic = array(


The native only conversion function is whether to return the first letter.
Extended support
1. Return format [all: full pinyin|first: initial letter|one: only the first letter of the first character]
2. Placeholder for unrecognized character replacement (original version Hard-coded is _ )
3. Allowed regular control of non-Chinese characters (the original hard-coded 0-9a-zA-Z, spaces are not supported)

is used by his pinyin. php ~ 206KB The UTF8 font library is only 106K after compression and expansion.
Of course, the performance is also close to his. In the 10,000 stress test, his 2.4s, after expansion, 2.8s, the loss is only 0.4s, so it can be ignored.

Disclaimer

All resources on this site are contributed by netizens or reprinted by major download sites. Please check the integrity of the software yourself! All resources on this site are for learning reference only. Please do not use them for commercial purposes. Otherwise, you will be responsible for all consequences! If there is any infringement, please contact us to delete it. Contact information: admin@php.cn

Related Article

PHP function code for converting Chinese characters into pinyinPHP function code for converting Chinese characters into pinyin

29Jul2016

:This article mainly introduces the function code for converting Chinese characters into pinyin in PHP. Students who are interested in PHP tutorials can refer to it.

What is the code for converting Chinese characters to Pinyin in PHP?What is the code for converting Chinese characters to Pinyin in PHP?

04Apr2023

In recent years, with the continuous development of the Internet, websites and APPs have become an indispensable part of people's daily lives. Among them, the Chinese character to Pinyin conversion function is becoming more and more commonly used in various situations, which also prompts developers to continuously develop new Chinese character to Pinyin codes to enrich the performance capabilities of this function. As a programming language widely used in website development, PHP's powerful text processing capabilities, coupled with numerous pinyin code libraries, also make it an ideal language for converting Chinese characters into pinyin. In this article, we will take an in-depth look at the Chinese character to Pinyin code in PHP

Function code for converting Chinese characters into pinyin in php_PHP tutorialFunction code for converting Chinese characters into pinyin in php_PHP tutorial

21Jul2016

Function code for converting Chinese characters into Pinyin in PHP. Click here to download the source file and copy the code. The code is as follows: function Pinyin($_String, $_Code='gb2312') { $_DataKey = "a|ai|an|ang|ao|ba|bai|ban|bang|bao|bei| ben|beng|bi|bian|biao|bie|bin

Java example of converting Chinese characters into PinyinJava example of converting Chinese characters into Pinyin

11Jan2017

This article mainly introduces relevant information on examples of converting Chinese characters into pinyin in Java. Friends in need can refer to it.

Code for converting Chinese characters into pinyin under PHP Page 1/2_PHP TutorialCode for converting Chinese characters into pinyin under PHP Page 1/2_PHP Tutorial

21Jul2016

Page 1/2 of the code for converting Chinese characters into pinyin under PHP. Copy the code as follows: ?php $d = array( array("a",-20319), array("ai",-20317), array("an",-20304), array("ang",-20295 ), array("ao",-20292), array("ba",-20283), array("bai",-202

Code for converting Chinese characters into pinyin under presentationfontcache.exe PHP Page 1/2Code for converting Chinese characters into pinyin under presentationfontcache.exe PHP Page 1/2

29Jul2016

presentationfontcache.exe: presentationfontcache.exe Code for converting Chinese characters into pinyin under PHP Page 1/2: Copy the code as follows:

See all articles