Syntax:
SUBSTR (string to be intercepted, 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, it is intercepted from the start position to the last
First Look at the example from left to right:
1, from the 2nd character intercept to the last
Copy Code code as follows:
$result = substr ("abcdef", 1);
Echo ($result);
The output is: bcdef
2, starting from the 2nd character Intercept 3
Copy Code code as follows:
$result = substr ("abcdef", 1,3);
Echo ($result);
The output is: BCD
Intercept from right to left:
1. Intercept 1 characters from right to left
Copy Code code as follows:
$result = substr ("abcdef",-1);
Echo ($result);
The output is: F
2. Intercept 2 characters from right to left
Copy Code code as follows:
$result = substr ("ABCdef",-2);
Echo ($result);
The output is: EF
3, from the right 3rd character to intercept the left 1 characters
Copy Code code as follows:
$result = substr ("abcdef", -3,1);
Echo ($result);
The output is: D