PHP RTrim () function use some abnormal phenomena in the process

Source: Internet
Author: User
Tags rtrim
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 .

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.