note 93052 deleted from function.strpos by danbrown
| From: | danbrown@php.net | Date: | Fri, 21 Aug 2009 13:36:10 +0000 |
| Subject: | note 93052 deleted from function.strpos by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-159744@lists.php.net to get a copy of this message | ||
Note Submitter: cr at example dot com
----
ah dot d: To save iterating over every character and do without a couple of "if" blocks,
as well as to make the "not found" return value be false like that of strpos(), and, like
strpos(), generate a warning if $offset is greater than strlen($haystack) or less than zero:
<?php
function strpos_all($haystack, $needle, $offset = 0)
{
while (($offset = strpos($haystack, $needle, $offset)) !== false) {
$result[] = $offset++;
}
return isset($result) ? $result : false;
}
?>