[英]How to determine if $match is in $string?
$string = "Test String for the test";
$match = "test string";
如何确定$ match是否在$ string中?
您可以使用stripos
通过不区分大小写的搜索在$string
找到$match
的位置:
$pos = stripos($string, $match);
请注意将其与类型安全的比较运算符(例如===
或!==
进行比较 。 因为在这种情况下,如果$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.