Strpos With an Array of Needles
Here’s a quick function to search a string for the position of several string occurrences. Once one is found, it returns the position.
// strpos with an array of $needles
function strposa($haystack, $needles) {
if (is_array($needles)) {
foreach ($needles as $str) {
if (is_array($str)) {
$pos = strposa($haystack, $str);
} else {
$pos = strpos($haystack, $str);
}
if ($pos !== FALSE) {
return $pos;
}
}
return FALSE;
} else {
return strpos($haystack, $needles);
}
}