The asp and asp functions that intercept strings are simple and easy to understand: left and right. in php, truncating strings from left to right is a function: substr syntax:
Substr (string to be intercepted, start position, and truncation length)
The start position starts from 0. if you want to extract from the first character, the start position parameter is 0.
The last parameter is optional. if only the start position is provided, it is truncated from the start position to the end.
Let's take a look at the example from left to right:
1. capture from 2nd characters to the end
$ Result = substr ("abcdef", 1); echo ($ result );
The output result is bcdef.
2. extract 3 from 2nd characters
$ Result = substr ("abcdef", 1, 3); echo ($ result );
The output result is bcd.
Truncate from right to left:
1. extract 1 character from right to left
$ Result = substr ("abcdef",-1); echo ($ result );
Output result: f
2. extract 2 characters from right to left
$ Result = substr ("abcdef",-2); echo ($ result );
Output result: ef
3. extract 1 character from the right side of 3rd characters to the left
$ Result = substr ("abcdef",-3, 1); echo ($ result );
For more information about how to use php to extract strings from right to left/from left to right, refer to the PHP Chinese website!