PHP manual note [message #169880] |
Wed, 29 September 2010 08:34 |
jrobinss
Messages: 3 Registered: September 2010
Karma: 0
|
Junior Member |
|
|
Hi all,
I've posted a new note on the manual page:
http://www.php.net/manual/en/function.strpos.php
It never appeared. Does anyone have a hint as to what didn't work out?
I'm wondering whether it's more likely to be...
* because the note was useless or badly formulated
* because the validation of new notes is done rarely
* for some other reason.
My only motivation was to be useful to others, so it's really not
dramatic that it didn't appear. It's just intriguing.
For what it's worth, here's the gist of the message, an alternative,
recursive, version of the "function for counting the number of
occurrences of the needle into the stack" (note by Nikolay Christov).
I find it more elegant, but YMMV.
/**
* Computes the number of times a string is found in another one.
* Never returns false or true or null, returns a number.
*/
function strinpos($haystack, $needle, $offset = 0) {
$pos = stripos($haystack, $needle, $offset);
if ($pos === false) { // end recursion test
return 0;
}
return 1 + strinpos($haystack, $needle, $pos + 1);
}
// example call (untested, typed directly here for the newsgroup post)
$numberOfOccurences = strinpos("it is a long long way", "long"); //
returns 2
|
|
|