繁体   English   中英

如何确定$ match是否在$ string中?

[英]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

使用strpos检查它是否在字符串中。 API链接

如果不区分大小写,请使用stripos API链接

使用stristr($haystack, $needle)http : stristr($haystack, $needle)

$boolean = stristr($string, $match);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM