伙计们,我是PHP新手,请帮助!谢谢你。可以说我需要对一些而不是典型的单词进行音节处理:text =“ abce dfia jicd fbii”。条件是:如果我们在文本中有两个彼此靠近的辅音,例如“ bc”,“ df”,“ cd”或“ fb”,则需要用插入符“-”将它们分开。因此输出必须为:“ ab-ce d-fia jic-d f-bii”。我的输出是:“ abcei-idfiai-ijicdi-ifbii”。我做错了什么?请帮忙!
$text= "abce dfia jicd fbii";
$letters_1= array("a","e","i","j");
$letters_2= array("b","c","d","f");
$insert= "-";
for ($x=0; $x<strlen($text); $x++) {
foreach($letters_2 as $letter => $value) {
if ($letter==$text[$x] and $value==$value) {
$new_text= str_replace(" ", $text[$x].$insert.$text[$x], $text);
}
}
}
echo $new_text;
我期望输出:“ ab-ce d-fia jic-d f-bii”