This article mainly introduced PHP function RTrim () Use of the strange phenomenon, combined with specific examples of the PHP function RTrim in the process of character matching problems and solutions, to further understand the principle of rtrim function and the use of skills, the need for friends can refer to the next
The examples in this paper describe the strange phenomenon in the use of PHP function RTrim (). Share to everyone for your reference, as follows:
There is rtrim()
a strange problem with the function today:
echo RTrim (' <p></p> ', ' </p> '); The output is <pecho ltrim (' www.php.cn ', ' www. '); Output is php.cn
The above output is a bit surprising, originally I think the first line should output <p>, and the second row output jb51.net.
This problem has been tangled up in me for a long time, has not found the reason, later in the handbook found the answer:
RTrim () is replaced with a character, not as a string. </p>6 characters will be replaced from right to left, and then to the left, because > is also contained in the string (</p>) of the second argument of Rtirm (), so it is also replaced, and when it goes to the left, it encounters P, P is not included in the string of the second argument. So replace stop, output <p.
If this is understood, the output from the second line is expected. Oh...... The handbook has been written clearly. Original:
You can also specify the characters your want to strip, by means of the charlist parameter. Simply list all characters so want to be stripped. With.. You can specify a range of characters.
Thus, and the rtrim
ltrim
trim
second parameter is matched as a set of character lists. This is not the same as the substitution of functions we have known in the past str_replace
.