$string = "Test String for the test";
$match = "test string";
How to determine if $match is in $string?
You can use stripos
to find the position of $match
in $string
with a case-insensitive search:
$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
.
使用stristr($haystack, $needle)
: http : stristr($haystack, $needle)
$boolean = stristr($string, $match);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.