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

发表于:2007-07-01来源:作者:点击数: 标签:
? $rest = substr(abcdef, 1); // returns bcdef echo @#substr(abcdef, 1) returns @# . $rest . br; $rest = substr(abcdef, 1, 3); // returns bcd echo @#substr(abcdef, 1, 3) returns @# . $rest . br; $rest = substr(abcdef, -1); // returns f echo
<?
$rest = substr("abcdef", 1); // returns "bcdef"
echo @#substr("abcdef", 1) returns @# . $rest . "<br>";
$rest = substr("abcdef", 1, 3); // returns "bcd"
echo @#substr("abcdef", 1, 3) returns @# . $rest . "<br>";
$rest = substr("abcdef", -1); // returns "f"
echo @#substr("abcdef", -1) returns @# . $rest . "<br>";
$rest = substr("abcdef", -2); // returns "ef"
echo @#substr("abcdef", -2) returns @# . $rest . "<br>";
$rest = substr("abcdef", -3, 1); // returns "d"
echo @#substr("abcdef", -3, 1) returns @# . $rest . "<br>";
$rest = substr("abcdef", 1, -1); // returns "bcde"
echo @#substr("abcdef", 1, -1) returns @# . $rest . "<br>";
?>

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

原文转自:http://www.ltesting.net