I prefer to use strpos
$needle='appy';
$haystack='I\'m feeling flappy, and you?';
if(strpos($haystack,$needle)!==false){
}
If you want it to ignore case, use stripos .
, , , 0 0. , false, , .
,
Boolean , , FALSE, 0 ". " " . === .
, strpos . Warning: strpos() expects parameter 1 to be string, array given 1Warning: strpos(): needle .
, , .
$needles=array('hose','fribb','pancake');
$haystack='Where are those pancakes??';
foreach($needles as $ndl){
if(strpos($haystack,$ndl)!==false){ echo "'$ndl': found<br>\n"; }
else{ echo "'$ndl' : not found<br>\n"; }
}
... , .
$haystack='Where are those pancakes??';
$match=preg_match('#(hose|fribb|pancake)#',$haystack);
//$match is now int(1)
, preg_match_all, , , total.
$all_matches=preg_match_all('#(hose|fribb|pancake)#',$haystack,$results);
//all_matches is int(2). Note you also have $results, which stores which needles matched.
. () , | "". # . , , , ! , , , . , .