2016-11-21 46 views
-1

我有一個包含重音字母的字符串替換。我還使用了一個標準化器,以便我具有相同的編碼,因爲我需要它們用於輸出,所以我無法刪除變音符號。我的代碼:在php代碼中帶重音字母的字符串變異

$word = array("bā","ba"); 

for($i=0;$i<count($word);$i++) 
{ 

    $accented = array("ā","ē","ī","ō","ū"); 

    $last = substr($word[$i],-1); 


    if ( in_array($last,$accented)) { // replacement of the array with the accented letters 
     $word[$i] = rtrim("x",$word[$i]); 
    } 



} 

我該如何修改我的代碼以使其適用於重音字母?

+1

確定。你的問題是什麼? –

+0

它與它有什麼關係?數據庫插入或? – 2016-11-21 20:44:39

+0

@FelippeDuarte編輯 –

回答

2

使用mb_substr

$last = mb_substr($word[$i],-1); 

它將與accenteded字母正常工作。

輸出將被

Array (
    [0] => x 
    [1] => bam 
)