如何用php检测给定单词的第二个元音,并按照辅音修剪单词?我尝试使用preg_match函数,但无法找到合适的解决方案。
//given word
$string = "engineering";
//output should be
echo "engin";
答案 0 :(得分:2)
实际上我没有得到你想要的东西,但我认为这可能有用
$yourString = "engineering";
$vowels = array("a", "e", "i", "o", "u", "A", "E", "I", "O", "U");
$occured = 0;
$output = "";
for($i=0;$i<strlen($yourString);$i++)
{
if(in_array($yourString[$i],$vowels) && ++$occured > 2) break;
$output .= $yourString[$i];
}
print $output;