note 115177 deleted from function.strpos by cmb
| From: | cmb@php.net | Date: | Sun, 02 Jun 2019 09:00:36 +0000 |
| Subject: | note 115177 deleted from function.strpos by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-211173@lists.php.net to get a copy of this message | ||
Note Submitter: andrew dot macrobert+php at gmail dot com
----
This function finds ALL occurrences of a substring, returning an array of indexes referring to the
start of each occurrence. Overlapping subtrings are not included.
<?php
function strpos_all($haystack, $needle) {
$instances = array();
$offset = 0;
while(($offset = strpos($haystack, $needle, $offset)) !== FALSE) {
$instances[] = $offset;
$offset += strlen($needle);
}
return $instances;
}
?>