PHP string function learning substr(), string substr_PHP tutorial

WBOY
Release: 2016-07-13 10:00:08
Original
878 people have browsed it

php string function learning substr(), string substr

/*
Definition and Usage
The substr() function returns the extracted substring, or FALSE on failure.

Grammar
substr(string,start,length)

Parameter Description
string required. Specifies a part of the string to be returned.
start
Required. Specifies where in the string to begin.
Non-negative number - starting from the start position of the string, counting from 0.
Negative - Starts characters start from the end of string.
If the length of string is less than or equal to start, FALSE is returned.

length
Optional. Specifies the length of the string to be returned. The default is until the end of the string.
Positive number - up to length characters starting at start (depending on the length of string).
Negative number - remove length characters from the end of string
If length is provided with a value of 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 . "
";
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/974672.htmlTechArticlephp string function learning substr(), string substr php /* Definition and usage substr() function return The extracted substring, or FALSE on failure. Syntax substr(string,st...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template