Mit dieser Funktion lassen sich alle Vorkommnisse in von $needle in $haystack finden. Zurückgegeben wird ein Array mit den Positionen:
function strpos_all($haystack, $needle)
{
$lastPos = 0;
$positions = array();
while (($lastPos = strpos($haystack, $needle, $lastPos))!== false) {
$positions[] = $lastPos;
$lastPos = $lastPos + strlen($needle);
}
return $positions;
}
// Aufruf
$str_positions=strpos_all('a', 'abcd ab abcdefg abcde');