note 11903 deleted from function.strpos by jimw

From: Date: Fri, 14 Dec 2001 20:05:43 +0000
Subject: note 11903 deleted from function.strpos by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-22698@lists.php.net to get a copy of this message
I needed a function to find the occurances of a string in another, so I thought I should share it. From this you can deduce: 1. The number of occurances: count(occurances($needle, $haystack) 2. Where they occur (duh!) function occurances($needle, $haystack) { while (strpos($haystack, $needle, $last) !== false) { $i[] = strpos($haystack, $needle, $last); $last = $i[count($i) - 1] + 1; } return $i; }

« previous php.notes (#22698) next »