PHP String Function Learning substr ()
This article mainly introduces the PHP string function learning substr (), this article explains its definition and usage, parameter description, hints and comments, as well as a number of use examples, the need for friends can refer to the following
/*
Definition and usage
The substr () function returns the extracted substring, or FALSE on failure.
Grammar
SUBSTR (String,start,length)
Parameter description
string is required. A string that specifies the part to return.
Start
Necessary. Specifies where to start the string.
Non-negative-starts from the start position of string and is calculated from 0.
Negative number-starts at the end of the string, starting at the start of the first character.
If the length of the string is less than or equal to start, FALSE is returned.
Length
Optional. Specifies the length of the string to return. The default is until the end of the string.
Positive number-includes a maximum of length characters (depending on the length of the string) starting at start.
Negative number-Removes the forward length character from the end of the string
If a length of value 0,false or NULL is provided, an empty string is returned.
*/
$str = "ABCDEFGHIJKLMN";
$rest = substr ($str, 0); Back to "ABCDEFGHIJKLMN"
Echo $rest. "
";
$rest = substr ($str, 1, 3); Returns "BCD"
Echo $rest. "
";
$rest = substr ($str,-3); Back to "LMN"
Echo $rest. "
";
$rest = substr ($str,-3, 2); Return to "LM"
Echo $rest. "
";
$rest = substr ($str, 1,-3); Back to "Bcdefghijk"
Echo $rest. "
";
$rest = substr ($str,-7,-3); Back to "Hijk"
Echo $rest. "
";
?>
http://www.bkjia.com/PHPjc/975118.html www.bkjia.com true http://www.bkjia.com/PHPjc/975118.html techarticle PHP String Function Learning substr () This article mainly introduces the PHP string function learning substr (), this article explains its definition and usage, parameter description, hints and comments, as well as several make ...