: 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