This article mainly introduces the substr () function parameter description and usage in PHP, analyzes the meaning of each parameter in the substr () function in the instance form, and illustrates its corresponding usage, and the friend who needs can refer to the following
The examples in this paper describe the substr () function parameter description and usage in PHP. Share to everyone for your reference. Specific as follows:
String substr (string $string, int $start [, int $length]), which can be used to find a matching string or character in a longer string, $string the string to be processed, $start the position to start the selection, $length is the length to select.
$length read characters from left to right for positive data.
When the $length is negative, the characters are read right-to-left.
String required, which specifies the strings to return a portion of.
Start is required to specify where the string begins.
Charlist Optional, which specifies the length of the string to return, by default until the end of the string.
Positive number-starts at the specified position in the string
Negative number-starts at the specified position from the end of the string
0-Starts at the first character in a string
The PHP instance code is as follows:
The code is as follows:
$rest _1 = substr ("abcdef", 2);//returns "Cdef" $rest _2 = substr ("ABCdef",-2);//R Eturns "EF" $rest 1 = substr ("abcdef", 0, 0); Returns "" $rest 2 = substr ("abcdef", 0, 2); Returns "AB" $rest 3 = substr ("abcdef", 0,-1); Returns "ABCDE" $rest 4 = substr ("abcdef", 2,0); Returns "" $rest 5 = substr ("abcdef", 2,2); Returns "CD" $rest 6 = substr ("ABCdef", 2,-1); Returns "CDE" $rest 7 = substr ("abcdef", -2,0); Returns "" $rest 8 = substr ("abcdef", -2,2); Returns "EF" $rest 9 = substr ("abcdef", -2,-1); Returns "E"