Nicer way to check if string contains all words from an array
You could use something like this:

$string = 'Hello, people at Stackoverflow';
$array = array('Hello', 'People');
$i = count(array_intersect($array, explode(" ", preg_replace("/[^A-Za-z0-9' -]/", "", $string))));
echo ($i) ? "found ($i)" : "not found";


Outputs:


  found (1)


(array_intersect is case sensitive)

Or if you'd like to make it a function, then you could do something like this:

function contains($needles, $haystack) {
    return count(array_intersect($needles, explode(" ", preg_replace("/[^A-Za-z0-9' -]/", "", $haystack))));
}

$string = 'Hello, people at Stackoverflow';
$array = array('Hello', 'People');
$i = contains($array, $string);
echo ($i) ? "found ($i)" : "not found";