Substr () function in php, and substr function in php

Source: Internet
Author: User

Substr () function in php, and substr function in php

// Substr ($ str, startIndex, length)

// The direction of the screenshot is from left to right.

// If the length is not specified, it is intercepted to the last one by default.

// The length is the exact number, and the negative value is the index (the maximum length)

// Note that startIndex starts from 0.

// The length includes the characters on startIndex. The length is 2, namely, startIndex and startIndex + 1.

Echo substr ('abcdef ',-4); // start is-4, which starts from the second to the last. Therefore, cdef is returned.

Echo '<br/> ';

Echo substr ('abcdef', 0); // The value 0 indicates that abcdef starts from the first one.

Echo '<br/> ';

Echo substr ('abcdef', 1, 3); // three characters starting from the second, bcd

Echo '<br/> ';

Echo substr ('abcdef',-3, 2); // two characters starting from the last three, de

Echo '<br/> ';

Echo substr ('abcdef ',-3,-2); // starts from the third to the second to the last, and does not include the second to the last, d

 

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.