Expanding on Weedpacket's idea, here's a function that mimics strpos(), taking the search values in an array. It returns the position of the first-found array element (false if none is found), and the string can be stepped through using $offset. It also triggers a warning if the offset is invalid.
function strarrpos($str, $char_arr, $offset = 0)
{
$found = false;
foreach ($char_arr as $char) {
if (($pos = strpos($str, $char, $offset)) !== false) {
$pos_arr[] = $pos;
$found = true;
}
}
if ($found) {
return min($pos_arr);
} else {
return false;
}
}
Example:
$string = 'adcde,defgH';
$chars = array('xy', 'de', 'H', ',');
$pos = 0;
while (($pos = strarrpos($string, $chars, $pos)) !== false) {
echo $pos . '<br />';
$pos++;
}