Home >Backend Development >PHP Tutorial >String PHP implementation method to intercept string from right to left/from left to right
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, the starting position parameter is 0.
The last parameter is optional, If only the starting position is provided, then intercept from the starting position to the end
Look at the example of intercepting from left to right:
1. Intercept from the second character to the end
Copy the code The code is as follows:
$ result = substr ("abcdef", 1);
echo($result);
Copy the 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);
Copy the code The code is as follows:
$result = substr ("abcdef", -2);
echo($result);
Copy code The code is as follows:
$result = substr (“abcdef”, -3,1);
echo($result);
The above introduces the implementation method of string PHP intercepting strings from right to left/from left to right, including string content. I hope it will be helpful to friends who are interested in PHP tutorials.