PHP substr () function parameter description and usage example, substr parameter description
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:
Copy the Code code as follows: $rest _1 = substr ("abcdef", 2); Returns "Cdef"
$rest _2 = substr ("ABCdef",-2); Returns "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"
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/912290.html www.bkjia.com true http://www.bkjia.com/PHPjc/912290.html techarticle php substr () function parameter description and usage examples, substr parameter description This article describes the substr () function parameter description and usage in PHP. Share to everyone for your reference. Specific as follows: ...