Php string function learning substr (). Php string function learning substr () This article mainly introduces php string function learning substr (), this article explains its definition and usage, Parameter descriptions, prompts and comments, and several substr () methods for learning php string functions ()
This article mainly introduces substr () in php string function Learning. This article describes its definition and usage, Parameter descriptions, prompts and comments, and multiple examples, for more information, see
/*
Definition and usage
The substr () function returns the extracted substring, or FALSE if it fails.
Syntax
Substr (string, start, length)
Parameter description
String is required. Specifies that a part of the string is to be returned.
Start
Required. Specifies where the string starts.
Non-negative-starts from the start position of the string and starts from 0.
Negative number-start from the start character at the end of string.
If the string length is less than or equal to start, FALSE is returned.
Length
Optional. Specifies the length of the string to be returned. The default value is until the end of the string.
Positive number-start from start can contain a maximum of length characters (depending on the length of string ).
Negative number-remove the length of the forward character from the end of the string
If the length is 0, FALSE, or NULL, an empty string is returned.
*/
$ Str = "abcdefghijklmn ";
$ Rest = substr ($ str, 0); // return "abcdefghijklmn"
Echo $ rest ."
";
$ Rest = substr ($ str, 1, 3); // return "bcd"
Echo $ rest ."
";
$ Rest = substr ($ str,-3); // return "lmn"
Echo $ rest ."
";
$ Rest = substr ($ str,-3, 2); // return "lm"
Echo $ rest ."
";
$ Rest = substr ($ str, 1,-3); // return "bcdefghijk"
Echo $ rest ."
";
$ Rest = substr ($ str,-7,-3); // return "hijk"
Echo $ rest ."
";
?>
This article mainly introduces the php string function learning substr (). This article explains its definition and usage, parameter description, prompts and comments, and multiple Enis...