Description of substr () function parameters and usage examples in php, and description of substr parameters. The substr () function parameter description and usage example in php. the substr parameter description in this article describes the substr () function parameter description and usage in php. Share it with you for your reference. Details are as follows: Description of substr () function parameters and usage examples in php, and description of substr parameters
This example describes the parameters and usage of the substr () function in php. 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.
Examples of callback () function parameters and usage. the substr parameter description examples in this article describe the substr () function parameters and usage in php. Share it with you for your reference. Details :...