[英]How to determine if $match is in $string?
$string = "Test String for the test";
$match = "test string";
How to determine if $match is in $string? 如何确定$ match是否在$ string中?
You can use stripos
to find the position of $match
in $string
with a case-insensitive search: 您可以使用stripos
通过不区分大小写的搜索在$string
找到$match
的位置:
$pos = stripos($string, $match);
Note to compare this with a type-safe comparison operator like ===
or !==
. 请注意将其与类型安全的比较运算符(例如===
或!==
进行比较 。 Because if $match
is at the begin of $string
like in this case, stripos
returns 0
and (boolean) 0 === false
. 因为在这种情况下,如果$match
在$string
的开头,则stripos
返回0
并且(boolean) 0 === false
。
使用stristr($haystack, $needle)
: http : stristr($haystack, $needle)
$boolean = stristr($string, $match);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.