/ Published in: PHP
URL: http://www.php.net/manual/en/function.strpos.php#96576
Jaim Thorn\'s handy iterating string searcher.
Expand |
Embed | Plain Text
/** * Returns the position of the $nth occurrence of $needle in $haystack, or false if it doesn't exist, or false when illegal parameters have been supplied. * * @param string $haystack the string to search in. * @param string $needle the string to search for. * @param integer $nth the number of the occurrence to look for. * @param integer $offset the position in $haystack to start looking for $needle. * @return MIXED integer either the position of the $nth occurrence of $needle in $haystack, * or boolean false if it can't be found. */ function strnpos( $haystack, $needle, $nth, $offset = 0 ) { { return false; } // $offset is incremented in the call to strpos, so make sure that the first call starts at the right position by initially decrementing $offset. --$offset; do { } while( --$nth && false !== $offset ); return $offset; }
You need to login to post a comment.
