Home  >  Article  >  Backend Development  >  把汉字转换为拼音,并让每个汉字的首字母大写

把汉字转换为拼音,并让每个汉字的首字母大写

WBOY
WBOYOriginal
2016-06-23 14:39:172746browse

例如大连,我转换为dalian,字母让转换为D,l转换为L,并且其他的字母还是小写


回复讨论(解决方案)

有大神帮忙解决吗?求解决

利用 pinyin.dat 对照表的汉字转拼音的代码,前些时候讨论过。你可以找一下
php 提供了 ucfirst 函数用于大写单词首字母
echo ucfirst('hello'); //Hello

提供一种思路,先转拼音,
比如 
大连 => da lian
再用ucwords()把每个单词的首字母转换为大写
da lian => Da Lian
最后去掉中间空格
Da Lian => DaLian

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