PHP汉字转拼音?如何把每个汉字拆分出来?

来源:百度知道 编辑:UC知道 时间:2024/06/30 05:27:20
我有一个汉字与拼音的对照表,格式是这样的:
阿a,啊a,茬cha,茶cha,嵖cha,
我想把每个要转换的汉字分别提出来对照获得拼音[preg_match()+substr(),不知道是否这个办法太笨,希望高人能给出更简单的办法],但我不知道如何把每个汉字分别提取出来.求高人指教!

使用explode就可以,例如:

<?php
$s='阿a,啊a,茬cha,茶cha,嵖cha';
foreach(explode(',',$s) as $code){
$ch=substr($code,0,2);
$code=substr($code,2);
echo "$ch\t$code<br>\n";
}
?>

使用explode就可以,例如:

<?php
$s='阿a,啊a,茬cha,茶cha,嵖cha';
foreach(explode(',',$s) as $code){
$ch=substr($code,0,2);
$code=substr($code,2);