2016-11-21 52 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 
)