2014-08-31 17 views
1

我有一個PHP函數,當$word_two以元音開頭時,它刪除最後一個字母$word_one,並將這個單詞放進一個apostroph。但是用法語元音é它不起作用,儘管我使用mb_strtolower, 'UTF-8'mb_strtolower不能與法語元音一起使用é

我不想更改$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; 
} 

例如:以Unicode模式(u

$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

UTF-8也是源代碼嗎? – 2014-08-31 17:30:04

+0

@dolan我想是這樣,例如'$ Ind ['I'] = array('étais','étais','était','étions','étiez','étaient');' – Grischa 2014-08-31 17:35:06

+0

你能給我一個例子的用法? – 2014-08-31 17:40:34

回答

3

preg功能通常比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"; 
相關問題