Reputation: 1520
how to find if this string :
132,139,150,166,176
is in this one? :
132,139,150,166,176,131,140,151,165,175
Upvotes: 6
Views: 5119
Reputation: 454922
You can use strpos function to find the occurrence of one string within another.
$str1 = '132,139,150,166,176,131,140,151,165,175';
$str2 = '132,139,150,166,176';
if( strpos($str1,$str2) !== false) {
// $str2 exists within $str1.
}
Note that strpos
will return 0
if $str2
is found at the beginning of $str1
which in fact is the case above and will return false
if not found anywhere.
You must use the identity operator !==
which checks both value and type to compare the return value with false
because:
0 !== false is true
where as
0 != false is false
Upvotes: 13