Weird usage of PHP function rtrim ()

Source: Internet
Author: User
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,ltrimAndtrimThe second parameter matches a group of characters. This is what we have known beforestr_replaceFunction replacement operations are different.

For more articles about the strange phenomenon in the use of PHP function rtrim (), please follow the PHP Chinese network!

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.