This article describes how to use strrev to flip Chinese garbled characters in PHP. you can use a custom function to traverse strings and set encoding formats to solve garbled characters, for more information about how to use strrev to flip Chinese garbled characters in PHP, see the following example. We will share this with you for your reference. The details are as follows:
Garbled characters may occur when I use strrve in PHP to flip Chinese characters
For example:
Header ("Content-Type: text/html; charset = utf-8"); echo strrev ("handling garbled characters when using the strrev () function ")."
";
The running result is:
�� Too many threads have been written) (verrts ��)
The solution is to rewrite a cnstrrev function.
Header ("Content-Type: text/html; charset = utf-8"); $ str = 'processing garbled characters when using the strrev () function '; function cnstrrev ($ str) {$ len = strlen ($ str); for ($ I = 0; $ I <$ len; $ I ++) {$ char = $ str {0 }; if (ord ($ char)> 127) // The ord () function obtains the ASCII code of the first character. if it is greater than 0xa0 (127) it is a Chinese character {$ I + = 2; // UTF-8 encoding, a Chinese character occupies three bytes if ($ I <$ len) {$ arr [] = substr ($ str, 0, 3); // in UTF-8 encoding, a Chinese character occupies three bytes. $ str = substr ($ str, 3) ;}} else {$ arr [] = $ char; $ str = substr ($ str, 1); // otherwise it is not Chinese, occupies one character} return join (array_reverse ($ arr); // returns an array in reverse element order:} echo $ str. '+ '. cnstrrev ($ str );
The running result is:
Handle garbled questions when using the strrev () function + the number of hours when the question code is messy)
I hope this article will help you with PHP programming.
For more articles about how PHP uses strrev to flip Chinese garbled text, refer to PHP's Chinese website!