Analysis of weird phenomena in the use of PHP function rtrim (), phprtrim

Source: Internet
Author: User

Analysis of weird phenomena in the use of PHP function rtrim (), phprtrim

This article describes how to use the PHP function rtrim. We will share this with you for your reference. The details are as follows:

Use todayRtrim ()The function encountered a strange problem:

Echo rtrim ('<p> </div>', '</div>'); // The output is <pecho ltrim ('www .jb51.net ', 'www. '); // The output is jb51.net.

The above output results are a little surprising. Originally, I thought the first line should be output <p>, and the second line should output 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. When you replace from right to left, the six characters </div> will be replaced, and then the six characters will be replaced, because> is also included in rtirm () in the string (</div>) of the second parameter, so it is replaced, and p is encountered when going to the left, p is not included in the string of the second parameter. So the replacement is stopped, and <p is output.

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,LtrimAndTrimThe second parameter matches a group of characters. This is what we have known beforeStr_replaceFunction replacement operations are different.

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.