strrchr
(PHP 4, PHP 5)
strrchr — Find the last occurrence of a character in a string
说明
string strrchr
( string $haystack
, string $needle
)
This function returns the portion of haystack
which
starts at the last occurrence of needle
and goes
until the end of haystack
.
参数
-
haystack
-
-
needle
-
If needle
contains more than one character,
only the first is used. This behavior is different from that of
strchr().
If needle
is not a string, it is converted to
an integer and applied as the ordinal value of a character.
返回值
This function returns the portion of string, or FALSE if
needle
is not found.
范例
Example#1 strrchr() example
<?php
// get last directory in $PATH
$dir = substr(strrchr($PATH, ":"), 1);
// get everything after last newline
$text = "Line 1\nLine 2\nLine 3";
$last = substr(strrchr($text, 10), 1 );
?>
strrchr()最后一次出现该符串到字符串结尾的所有字符
2009年05月20日 星期三 21:34
定义和用法
strrchr() 函数查找字符串在另一个字符串中最后一次出现的位置,并返回从该位置到字符串结尾的所有字符。
如果成失败,否则返回 false。
语法
strrchr(string,char)
参数 |
描述 |
string |
必需。规定被搜索的字符串。 |
char |
必需。规定要查找的字符。如果该参数是数字,则搜索匹配数字 ASCII 值的字符。 |
例子
例子 1
<?php echo strrchr("Hello world!","world") ; ?>
输出:
world!
例子 2
<?php echo strrchr("Hello world!",111) ; ?>
输出:
orld!
PHP String 函数
<?php echo strrchr("Hello world!<br>","world"); //world! echo strrchr("Hello world!<br>","l"); //ld! echo strrchr("Hello world!<br>","H"); //Hello world! echo strrchr("Hello world!<br>","e"); //ello world! echo strrchr("Hello world!<br>","llo"); //ld!(由这看来,他只认第一个字母.不认一整个字符串) echo strrchr("Hello world!<br>","ello"); //ello world! echo strrchr("Hellor world!<br>","or"); //orld! echo strrchr("Hello world!",111); //orld! ?>
|