簡體   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