Grammar:
SUBSTR (string to intercept, start position, intercept length)
The start position starts at 0, and if you want to intercept from the first character, the start position parameter is 0.
The last parameter is optional, and if only the start position is provided, then the end is intercepted from the start position
Let's look at the example of a left-to-right intercept:
1, from the 2nd character intercept to the last
Copy the Code code as follows:
$result = substr ("abcdef", 1);
Echo ($result);
The output is: bcdef
2, starting from the 2nd character interception of 3
Copy the Code code as follows:
$result = substr ("abcdef", 1,3);
Echo ($result);
The output is: BCD
To intercept from right to left:
1. Intercept 1 characters from right to left
Copy the Code code as follows:
$result = substr ("abcdef",-1);
Echo ($result);
The output is: F
2. Intercept 2 characters from right to left
Copy the Code code as follows:
$result = substr ("ABCdef",-2);
Echo ($result);
The output is: EF
3.1 characters to the left from the 3rd character on the right
Copy the Code code as follows:
$result = substr ("abcdef", -3,1);
Echo ($result);
The output is: D
The above describes the string php from right to left/left to right to intercept the string implementation method, including the content of the string, I hope that the PHP tutorial interested in a friend helpful.