note 87061 modified in function.strpos by thiago

From: Date: Tue, 18 Nov 2008 14:59:51 +0000
Subject: note 87061 modified in function.strpos by thiago
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-146648@lists.php.net to get a copy of this message
If you would like to find all occurences of a needle inside a haystack you could use this function strposall($haystack,$needle);. It will return an array with all the strpos's. <?php /** * strposall * * Find all occurrences of a needle in a haystack * * @param string $haystack * @param string $needle * @return array or false */ function strposall($haystack,$needle){ $s=0; $i=0; while (is_integer($i)){ $i = strpos($haystack,$needle,$s); if (is_integer($i)) { $aStrPos[] = $i; $s = $i+strlen($needle); } } if (isset($aStrPos)) { return $aStrPos; } else { return false; } } ?> --was-- If you would like to find all occurences of a needle inside a haystack you could use this function strposall($haystack,$needle);. It will return an array with all the strpos's. /** * strposall * * Find all occurrences of a needle in a haystack * * @param string $haystack * @param string $needle * @return array or false */ function strposall($haystack,$needle){ $s=0; $i=0; while (is_integer($i)){ $i = strpos($haystack,$needle,$s); if (is_integer($i)) { $aStrPos[] = $i; $s = $i+strlen($needle); } } if (isset($aStrPos)) { return $aStrPos; } else { return false; } } http://php.net/manual/en/function.strpos.php

« previous php.notes (#146648) next »