StrRev() Dosent Support UTF-8

后端 未结 3 883
长情又很酷
长情又很酷 2021-02-15 18:50

I\'m trying to make a code that replace Arabic text to be supported in non Arabic supported programs
in that i will be need to reverse the text after replace but its shows s

3条回答
  •  情歌与酒
    2021-02-15 19:15

    in order to make that strrev() support UTF-8 you need to use this Function

    function utf8_strrev($str){
        preg_match_all('/./us', $str, $ar);
        return join('', array_reverse($ar[0]));
    }
    

    so we going to chage strrev() in our code to utf8_strev() :

    $string = "اهلا بك";
    echo "$string 
    "; $Reversed = utf8_strrev($string); // here we have changed it echo "
    After Reverse

    "; echo "
    $Reversed";

    and the Result is :

    اهلا بك
    
    After Reverse
    
    
    كب الها
    

提交回复
热议问题