StrRev() Dosent Support UTF-8

后端 未结 3 869
长情又很酷
长情又很酷 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:13

    A more generic solution that handles all encodings, not only UTF-8:

    function mb_strrev ($string, $encoding = null)
    {
        if ( is_null($encoding) ) {
            $encoding = mb_detect_encoding($string);
        }
    
        $length   = mb_strlen($string, $encoding);
        $reversed = '';
    
        while ( $length-->0 ) {
            $reversed .= mb_substr($string, $length, 1, $encoding);
        }
    
        return $reversed;
    }
    

    Thanks to Kevin van Zonneveld

提交回复
热议问题