stristr()
函数在 PHP 中用于在字符串中查找子字符串,它会返回从开始位置到找到的子字符串的第一个匹配项之间的所有字符。默认情况下,stristr()
函数是区分大小写的。
如果你想在 stristr()
函数中忽略空格,可以在被搜索的字符串和要查找的子字符串两边都加上空格。这样,stristr()
函数就会将空格视为普通字符进行处理。例如:
$haystack = 'Hello World';
$needle = 'World ';
$result = stristr($haystack, $needle);
if ($result) {
echo "Found: " . $result; // 输出 "Found: World"
} else {
echo "Not found";
}
在这个例子中,我们在 haystack
和 needle
两边都加上了空格,这样 stristr()
函数就能正确地找到子字符串 “World” 了。