In this paper, we explain how PHP uses Strrev to reverse the problem of Chinese garbled. Share to everyone for your reference, as follows:
When you flip Chinese with strrve in PHP, garbled behavior occurs.
For example:
Header ("content-type:text/html; Charset=utf-8 "), Echo strrev (" Handling garbled problems using the Strrev () function ")." <br> ";
The result of the operation is:
鮗 copy 䄚 綗 protium) (verrts 翽 䆐 焤
The solution is to rewrite a cnstrrev function yourself.
Header ("content-type:text/html; Charset=utf-8 "), $str = ' handling garbled problem using Strrev () function '; function Cnstrrev ($str) { $len = strlen ($STR); for ($i = 0; $i < $len; $i + +) { $char = $str {0}; if (ord ($char) > 127)//ord () function takes the ASCII code of the first character, if it is greater than 0xa0 (127) then the Chinese character { $i +=2;//utf-8 encoding, a Chinese character is three bytes if ($i < $len) { $arr [] = substr ($str, 0, 3);//utf-8 encoding, a Chinese character occupies three bytes $str = substr ($str, 3); } } else { $arr [] = $char; $str = substr ($str, 1);//Otherwise non-Chinese, takes one character } } return Join (Array_reverse ($arr));//returns an array in reverse order of elements:}echo $ Str. ' + '. Cnstrrev ($STR);
The result of the operation is:
Handling garbled problems when using the Strrev () function + the number of hours of confusion in the question (Verrts)
I hope this article is helpful to you in PHP programming.