If you want to find one word in a string you would use strpos, but there can be a problem when you want to search for more than one word, then this code below would work for you.
1 2 3 4 5 6 7 8 9 10 |
function contains($needles, $haystack) { return count(array_intersect($needles, explode(" ", preg_replace("/[^A-Za-z0-9' -]/", "", $haystack)))); } $string = 'site security'; $array = array('building', 'site','security'); $i = contains($array, $string); echo ($i) ? "Keyword found" : "not found"; |