note 49739 modified in function.strpos by danbrown
| From: | danbrown@php.net | Date: | Sun, 17 May 2009 16:42:58 +0000 |
| Subject: | note 49739 modified in function.strpos by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-154882@lists.php.net to get a copy of this message | ||
If you want to get all positions in an array, you can use this function. If the optional parameter
count is especified, the function will put there the number of matches.
<?php
function strallpos($pajar, $aguja, $offset=0, &$count=null) {
if ($offset > strlen($pajar)) trigger_error("strallpos(): Offset not contained in
string.", E_USER_WARNING);
$match = array();
for ($count=0; (($pos = strpos($pajar, $aguja, $offset)) !== false); $count++) {
$match[] = $pos;
$offset = $pos + strlen($aguja);
}
return $match;
}
?>
--was--
If you want to get all positions in an array, you can use this function. If the optional parameter
count is especified, the function will put there the number of matches.
function strallpos($pajar, $aguja, $offset=0, &$count=null) {
if ($offset > strlen($pajar)) trigger_error("strallpos(): Offset not contained in
string.", E_USER_WARNING);
$match = array();
for ($count=0; (($pos = strpos($pajar, $aguja, $offset)) !== false); $count++) {
$match[] = $pos;
$offset = $pos + strlen($aguja);
}
return $match;
}
http://php.net/manual/en/function.strpos.php