This article mainly introduces the description and usage of substr () function parameters in php, analyzes the meaning of each parameter in substr () function in the form of an instance, and illustrates its usage, for more information about substr () function parameters in php, see the following example. Share it with you for your reference. The details are as follows:
String substr (string $ string, int $ start [, int $ length]), which can be used to search for matched strings or characters in a long string, $ string is the string to be processed, $ start is the start position, and $ length is the length to be selected.
$ Length: reads characters from left to right for positive data.
When $ length is negative, it reads characters from right to left.
String is required, which specifies that a part of the string is to be returned.
Start is required, specifying where the string starts.
Charlist (optional) specifies the length of the string to be returned. the default value is until the end of the string.
Positive number-start at the specified position of the string
Negative number-starting from the specified position at the end of the string
0-start at the first character in the string
The PHP instance code is as follows:
The code is as follows:
$ Rest_1 = substr ("abcdef", 2); // returns "cdef"
$ Rest_2 = substr ("abcdef",-2); // returns "ef"
$ Rest1 = substr ("abcdef", 0, 0); // returns ""
$ Rest2 = substr ("abcdef", 0, 2); // returns "AB"
$ Rest3 = substr ("abcdef", 0,-1); // returns "abcde"
$ Rest4 = substr ("abcdef", 2, 0); // returns ""
$ Rest5 = substr ("abcdef", 2, 2); // returns "cd"
$ Rest6 = substr ("abcdef", 2,-1); // returns "cde"
$ Rest7 = substr ("abcdef",-2, 0); // returns ""
$ Rest8 = substr ("abcdef",-2, 2); // returns "ef"
$ Rest9 = substr ("abcdef",-2,-1); // returns "e"
I hope this article will help you with PHP programming.