This article mainly introduces the strange phenomenon in the use of PHP function rtrim (), and analyzes the problems and solutions in the character matching process of php function rtrim in the form of examples, this helps you to further understand the principles and skills of the rtrim function. For more information, see the following example. We will share this with you for your reference. The details are as follows:
Use todayrtrim()
The function encountered a strange problem:
Echo rtrim ('',''); // The output is
The output result is a little unexpected. I thought the first line should be output.
The second line outputs jb51.net.
I have been entangled in this problem for a long time, but I have not found the cause. later I found the answer in the manual:
Rtrim () is replaced by characters rather than strings. Replacement from right to left
The six characters will surely be replaced, and> will be encountered when going to the left, because> is also included in the string of the second parameter of rtirm (
), So it is replaced. when p is encountered again to the left, p is not included in the string of the second parameter. So the replacement is stopped, and the output is
If you understand this, the output result of the second line is expected. Haha ...... The manual has been clearly written. Original article:
You can also specify the characters you want to strip, by means of the charlist parameter. Simply list all characters that you want to be stripped. With... you can specify a range of characters.
As you can see,rtrim
,ltrim
Andtrim
The second parameter matches a group of characters. This is what we have known beforestr_replace
Function replacement operations are different.
For more articles about the strange phenomenon in the use of PHP function rtrim (), please follow the PHP Chinese network!