Php string function substr () _ PHP Tutorial

Source: Internet
Author: User
The string function substr () in php (). Syntax of the string function substr () in php: stringsubstr (string $ stringint $ start [, int $ end]). This function is also intercepted in bytes (not characters, when intercepting Chinese characters, note that the string function substr () in php ()
Syntax: string substr (string $ string int $ start [, int $ end]). This function is also truncated by byte (not a character). Note the following when intercepting Chinese characters, in addition, the starting position of the truncation must be on the left of the ending position, that is, it is always intercepted from left to right.

$ Str = "Hello world! ";

Echo substr ($ str, 3 ),"
"; // Result lo world!

Echo substr ($ str, 3, 8 ),"
"; // Result lo wo

Echo substr ($ str,-6 ),"
"; // At this time, the second parameter is a negative number, indicating that it is truncated from the sixth position to the next position, and the result is world.

Echo substr ($ str,-6,-3 ),"
"; // When the third parameter is negative, it indicates the truncation length and the result is wor.

Substring () syntax: string substr (string $ string int $ start [, int $ end]). This function is also truncated by byte (not a character, when intercepting Chinese characters, pay attention to the following ,...

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.