PHP String Function Learning substr (), String substr
<?php
/*
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/974672.html www.bkjia.com true http://www.bkjia.com/PHPjc/974672.html techarticle PHP String Function Learning substr (), String substr PHP/* Definition and Usage substr () function returns the extracted substring, or FALSE on failure. Grammar substr (string,st ...