# Learning a new php function every day (1) substr ()

Source: Internet
Author: User
: This article mainly introduces # learning a new php function (1) substr () every day. if you are interested in the PHP Tutorial, refer to it. Recently, I found that my code writing efficiency is too low. Find the cause and find that most of the time I used it to find the usage of the function in the manual, but I forgot it immediately after I found it, and the second time I encountered this function again. A lot of time is wasted. Therefore, I decided to write a summary set and try to record the most frequently encountered function every day.

String substr (string $ string, int $ start [, int $ length])

This function is used to intercept a specified string. it is very powerful.

Param $ start

If start is not negative, the returned string starts from the start position of the string and starts from 0. For example, in the string "abcdef", the character at the position 0 is "a", and the character string at the position 2 is "c.
If start is a negative number, the returned string starts from the start character at the end of the string.
If the string length is less than or equal to start, FALSE is returned.

Param $ length

If a positive length is provided, the returned string can contain a maximum of length characters starting from start (depending on the length of the string ).
If a negative length is provided, many characters at the end of the string will be missed (if start is a negative number, it will be counted from the end of the string ). If start is not in this text, an empty string is returned.
If the length is 0, FALSE, or NULL, an empty string is returned.
If length is not provided, the returned substring starts from the start position until the end of the string.

Return value

Returns the extracted substring, or FALSE if it fails.

Example


   
   

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.