Php truncates a string from the right to the left to the right. Syntax: substr (string to be truncated, start position, and truncation length) start from 0. if you want to start intercepting from the first character, the start position parameter is 0. the last parameter is
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
Substring substr (string to be truncated, start position, and truncation length) start from 0. if you want to start intercepting from the first character, the start position parameter is 0. the last parameter is...