通过汉语拼音的规律实现汉语拼音的切分,采用php实现。
输入:一串连续的拼音,如zhongguo
输出:zhong guo
function split_func($str){
$vowel = array('a','e','i','o','u','v');;
$result = "";
$i = 0;
for($i = 0; $i < strlen($str); $i++){
if(in_array($str[$i], $vowel)){
$result .= $str[$i];
continue;
}else{
if($str[$i] != 'n'){
if ($i == 0)
{
$result .= $str[$i];
}
else
{
$result .= ' '.$str[$i];
}
if ((($i + 1) < strlen($str) and $str[$i] == 'z' or $str[$i] == 'c' or $str[$i] == 's')