string PHP Implementation of a right-to-left/left-to-right intercept string

Source: Internet
Author: User
Grammar:
SUBSTR (string to intercept, start position, intercept length)
The start position starts at 0, and if you want to intercept from the first character, the start position parameter is 0.
The last parameter is optional, and if only the start position is provided, then the end is intercepted from the start position
Let's look at the example of a left-to-right intercept:
1, from the 2nd character intercept to the last

Copy the Code code as follows:


$result = substr ("abcdef", 1);
Echo ($result);


The output is: bcdef
2, starting from the 2nd character interception of 3

Copy the Code code as follows:


$result = substr ("abcdef", 1,3);
Echo ($result);


The output is: BCD
To intercept from right to left:
1. Intercept 1 characters from right to left

Copy the Code code as follows:


$result = substr ("abcdef",-1);
Echo ($result);


The output is: F
2. Intercept 2 characters from right to left

Copy the Code code as follows:


$result = substr ("ABCdef",-2);
Echo ($result);


The output is: EF
3.1 characters to the left from the 3rd character on the right

Copy the Code code as follows:


$result = substr ("abcdef", -3,1);
Echo ($result);


The output is: D

The above describes the string php from right to left/left to right to intercept the string implementation method, including the content of the string, I hope that the PHP tutorial interested in a friend helpful.

  • 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.