mb_strtolower不适用于法语元音é [英] mb_strtolower doesn't work with french vowel é

查看:157
本文介绍了mb_strtolower不适用于法语元音é的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHP函数,当$word_two以元音开头时,该函数删除$word_one的最后一个字母并在该单词上加上撇号.但是对于法语元音é来说,它不起作用,尽管我将mb_strtolower, 'UTF-8'结合使用.

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'.

我不想更改$pers数组,因为对于$word_two并非以元音开头的单词,我也有一些组合.

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

示例:

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

推荐答案

preg Unicode模式(u)中的函数通常比mb_xxx更易于使用:

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

还要匹配que jewhatever je:

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

这篇关于mb_strtolower不适用于法语元音é的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆