我有一个PHP函数,它删除$word_one
的最后一个字母,当$word_two
以元音开头时,将一个叛逆者放到这个单词中。但是使用法语元音é它不起作用,尽管我使用mb_strtolower
和, 'UTF-8'
。
我不想更改$pers
数组,因为我还有$word_two
不以元音开头的单词的组合。
function French($word_one, $word_two) {
if (in_array(mb_strtolower($word_two{0}, 'UTF-8'), array('a', 'e', 'é', 'i', 'o')) and ($word_one == "je" or $word_one == "que je"))
// delete last letter in $word_one and add an apostrophe and all of $word_two é don't work
$output = substr($word_one, 0, -1) . '\'' . $word_two;
else
// other wise combine the words with a space in between
$output = $word_one . ' ' . $word_two;
return $output;
}
示例:
$pers = array('je', "tu", "il/elle/on", "nous", "vous", "ils/elles");
$que_pers = array("que je", "que tu", "qu'il/elle/on", "que nous", "que vous", "qu'ils/elles");
$Ind['I'] = array ('étais','étais','était','étions','étiez','étaient');
$Sub['Pré'] = array ('aie','aies','ait','ayons','ayez','aient');
echo ''.French($pers[0], $Ind['I'][0]).'';
echo ''.French($que_pers[0], $Sub['Pré'][0]).'';
答案 0 :(得分:3)
preg
函数(u
)通常比mb_xxx
更容易使用:
function French($word_one, $word_two) {
if($word_one == 'je' && preg_match('~^[aeéio]~ui', $word_two))
return "j'$word_two";
return "$word_one $word_two";
}
还要匹配que je
或whatever je
:
if(preg_match('~(.*)\bje$~ui', $word_one, $m) && preg_match('~^[aeéio]~ui', $word_two))
return "{$m[1]}j'$word_two";