The asp and asp functions that intercept strings are simple and easy to understand: left and right. in php, intercept string from left to right and intercept string from right to left is a function: substr.
The asp and asp functions that intercept strings are simple and easy to understand: left and right. in php, intercept string from left to right and intercept string from right to left 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
The Code is as follows:
$ Result = substr ("abcdef", 1 );
Echo ($ result );
The output result is bcdef.
2. extract 3 from 2nd characters
The Code is as follows:
$ 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
The Code is as follows:
$ Result = substr ("abcdef",-1 );
Echo ($ result );
Output result: f
2. Extract 2 Characters from right to left
The Code is as follows:
$ Result = substr ("abcdef",-2 );
Echo ($ result );
Output result: ef
3. extract 1 character from the right side of 3rd characters to the left
The Code is as follows:
$ Result = substr ("abcdef",-3, 1 );
Echo ($ result );
Output result: d