函数名:stristr() 适用版本:所有版本 用法:stristr()函数用于在字符串中查找子字符串,并返回从子字符串开始到字符串末尾的所有字符。该函数是大小写不敏感的。 语法:stristr(st...
函数名:stristr()
适用版本:所有版本
用法:stristr()函数用于在字符串中查找子字符串,并返回从子字符串开始到字符串末尾的所有字符。该函数是大小写不敏感的。
语法:stristr(string $haystack, mixed $needle, bool $before_needle = false): string|false
参数:
返回值:
示例:
$string = "Hello World!";
$substring = "WORLD";
$result = stristr($string, $substring);
echo $result; // 输出:World!
$string = "Hello World!";
$substring = "WORLD";
$result = stristr($string, $substring, true);
echo $result; // 输出:Hello
在第一个示例中,函数将忽略大小写,找到了子字符串"WORLD",并返回从子字符串开始到字符串末尾的所有字符"World!"。
在第二个示例中,通过设置$before_needle参数为true,函数返回子字符串之前的部分"Hello"。