I'm using preg_match to check if a string has a specific word in it:
$string = 'This string contains a few words that are in an array!';
$arr = ['string', 'few', 'words'];
if(preg_match('['.implode('|', $arr).']', $string)){
//do something if there is at least one word from the array inside that string
}
This is working quite nice but it will return true if there is at least one word and i need it to return true if there are at least two words from the array inside that string.
Can that be done in one step? If not, which way should i go from here to obtain that result?
Thank you!:D
preg_match('~\b(?:'.implode('|', $arr).')\b.*\b(?:'.implode('|', $arr).')\b~', $string)substr_countphp.net/manual/en/function.substr-count.phpsubstr_countfor multiple needles(and case insensitive) :-s. For example i want to checkstring: This is mine and yoursforarr: is, andso ifisandandare found in that string it will return true :-s