Home >Backend Development >PHP Tutorial >例子:php的substr函数真是强大(substr.php3)_PHP

例子:php的substr函数真是强大(substr.php3)_PHP

WBOY
WBOYOriginal
2016-06-01 12:36:24845browse

SUBSTR


$rest = substr("abcdef", 1); // returns "bcdef"
echo 'substr("abcdef", 1) returns ' . $rest . "
";
$rest = substr("abcdef", 1, 3); // returns "bcd"
echo 'substr("abcdef", 1, 3) returns ' . $rest . "
";
$rest = substr("abcdef", -1); // returns "f"
echo 'substr("abcdef", -1) returns ' . $rest . "
";
$rest = substr("abcdef", -2); // returns "ef"
echo 'substr("abcdef", -2) returns ' . $rest . "
";
$rest = substr("abcdef", -3, 1); // returns "d"
echo 'substr("abcdef", -3, 1) returns ' . $rest . "
";
$rest = substr("abcdef", 1, -1); // returns "bcde"
echo 'substr("abcdef", 1, -1) returns ' . $rest . "
";
?>

具体的使用可以看PHP的Manual中的function.substr.html。

Statement:
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