PHP intercepts string functions;

Source: Internet
Author: User

    1. <? PHP
    2. $str = "123456789";
    3. Echo substr ($str, 0, 3);//intercept 3-bit characters from the first character on the left: result: 123
    4. Echo substr ($str, 3, 3);//intercept 3-bit characters from the 3rd character on the left: result: 456
    5. ?>
[HTML]View PlainCopy  
    1. <? PHP
    2. $Rest = substr ("abcdef",-1); Return "F"
    3. $Rest = substr ("abcdef",-2); Back to "EF"
    4. $Rest = substr ("ABCdef",-3, 1);//return "D"
    5. ?>

[HTML]View PlainCopy 
    1. <? PHP
    2. $Rest = substr ("ABCdef", 0,-1); Back to "ABCDE"
    3. $Rest = substr ("ABCdef", 2,-1); Back to "CDE"
    4. $Rest = substr ("ABCdef", 4,-4); Return ""
    5. $Rest = substr ("ABCdef",-3,-1);//Return to "de"
    6. ?>

[HTML]View PlainCopy 
    1. <? PHP
    2. echo substr (' abcdef ', 1); Bcdef
    3. echo substr (' abcdef ', 1, 3); Bcd
    4. echo substr (' abcdef ', 0, 4); Abcd
    5. echo substr (' abcdef ', 0, 8); ABCdef
    6. echo substr (' abcdef ',-1, 1); F
    7. To access a single character in a string
    8. You can also use the brackets
    9. $string = ' abcdef ';
    10. echo $string [0]; A
    11. Echo $string [3]; D
    12. echo $string [Strlen ($string)-1]; F
    13. ?>

PHP intercepts string functions;

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.