Briefly describe the problem you are experiencing today:
In my code there is the following code snippet:
header("Content-type:text/html;charset=utf8"); echo rtrim("威、","、");
The original expectation is output "Wei". But backfired, output a few garbled. What is this for? Let me take it very carefully.
The first thing to know is the function of the RTrim function, and its second argument is a string, where each char will be taken out as the character to be removed. such as this:
echo rtrim("blakefezabc", "cab"); //output blakefez
Yes, the output is Blakefez.
The implementation of this function should also be relatively simple:
①, starting from the last character of the first argument, iterates to the left to determine if the byte is in the second argument.
②, if present, remove the byte, and proceed to the first step. If it does not exist, it ends.
Please note that I use bytes above. Yes, this function is a non-multibyte-safe function. That is, when some of the characters in our arguments are multi-byte, they produce unwanted results. such as the beginning of the RTrim ("Wei,", ","). Because "Wei" and "," are UTF8 encoded. That is, multibyte characters. Wherein, "Granville" encoding is 0xe5 0xa8 0x81, "," The encoding is 0xe3 0x80 0x81, so, in the RTrim function eye, it sees is: RTrim ("0xe5 0xa8 0x81 0xe3 0x80 0x81", "0xe3 0x80 0x81" So the result of the final output is 0xe5 0xa8, and then converted to UTF8 code, it becomes garbled.
'). addclass (' pre-numbering '). Hide (); $ (this). addclass (' has-numbering '). Parent (). append ($numbering); for (i = 1; i <= lines; i++) {$numbering. Append ($ ('
'). Text (i)); }; $numbering. FadeIn (1700); }); });
The above describes a pit of the RTrim function, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.