mb_strtolower doesn't work with french vowel é

偶尔善良 提交于 2019-12-11 12:07:01

问题


I have a PHP function, which delete the last letter of $word_one and put an apostroph to this word, when the $word_two begins with a vowel. But with the french vowel é it doesn't work, although I use the mb_strtolower with , 'UTF-8'.

I don't want to change the $pers array, because I have also combination for words where the $word_two doesn't begin with a vowel.

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;
}

example:

$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]).'';

回答1:


preg functions in unicode mode (u) are usually easier to use than 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";
}

To also match que je or whatever je:

if(preg_match('~(.*)\bje$~ui', $word_one, $m) && preg_match('~^[aeéio]~ui', $word_two))
    return "{$m[1]}j'$word_two";


来源:https://stackoverflow.com/questions/25594446/mb-strtolower-doesnt-work-with-french-vowel-%c3%a9

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!