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