Syntax:
substr (string to be intercepted, starting position, interception length)
The starting position starts from 0, if you want to intercept from the first character, then the starting position The parameter is 0.
The last parameter is optional. If only the starting position is provided, it will be intercepted from the starting position to the end.
First look at the example of intercepting from left to right:
1. Cut from the second character to the last
Copy the code The code is as follows:
$result = substr (“abcdef”, 1);
echo($result);
The output result is: bcdef
2. Intercept 3
starting from the 2nd character
Copy code The code is as follows:
$result = substr (“abcdef”, 1,3);
echo($result ; Copy the code
The code is as follows:
$result = substr ("abcdef", -1);
echo($result);
The output result is: f 2. Cut 2 characters from right to left
Copy the code
The code is as follows:
$result = substr (“abcdef”, -2);
echo($result);
The output result is: ef 3. From the 3rd character on the right to the left Intercept 1 character
Copy code
The code is as follows:
$result = substr ("abcdef", -3,1) ;
echo($result);
The output result is: d
http://www.bkjia.com/PHPjc/324732.html
www.bkjia.com
true
http: //www.bkjia.com/PHPjc/324732.html
TechArticle Syntax: substr (string to be intercepted, starting position, intercepting length) The starting position starts from 0, if you want Starting from the first character, the starting position parameter is 0. The last parameter is...