note 11903 added to function.strpos.php
| From: | tgg at bigpond dot net dot au | Date: | Tue, 13 Mar 2001 03:20:35 +0000 |
| Subject: | note 11903 added to function.strpos.php | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-12321@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;
}
http://www.php.net/manual/en/function.strpos.php