mb_stristr
(PHP 5 >= 5.2.0, PHP 7, PHP 8)
mb_stristr — 大小写不敏感地查找字符串在另一个字符串里的首次出现
说明
mb_stristr(
string
string
bool
?string
): string|false
string
$haystack
,string
$needle
,bool
$before_needle
= false
,?string
$encoding
= null
): string|false
mb_strstr() 查找了 needle
在 haystack
中首次的出现并返回 haystack
的一部分。
和 mb_strstr() 不同的是,mb_stristr() 是大小写不敏感的。
如果 needle
没有找到,它将返回 false
。
参数
返回值
返回 haystack
的一部分,或者 needle
没找到则返回 false
。
更新日志
版本 | 说明 |
---|---|
8.0.0 |
现在 needle 接受空字符串。
|
8.0.0 |
现在 encoding 可以为 null。
|
+添加备注
用户贡献的备注 1 note
nowfel dot terki at mailfence dot com ¶
2 years ago
Be aware that if needle is an empty string, mb_stristr return the haystack by default.
For exemple:
<?php
if (mb_stristr("foo", "")) {
echo "We enter in condition";
}
?>
Because in the above exemple the return of mb_stristr is "foo".
So if we do not want this kind of behaviour, we must set the third argument, ($before_needle) to true.
<?php
if (mb_stristr("foo", "", true)) {
echo "We do not enter in condition";
}
?>
It can be useful to know it, specially when needle is dynamic.