note 99951 deleted from function.strpos by danbrown

From: Date: Thu, 16 Sep 2010 15:43:57 +0000
Subject: note 99951 deleted from function.strpos by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-172645@lists.php.net to get a copy of this message
Note Submitter: JRobinss ---- To answer Nikolay Christov (01-Sep-2010 03:22), here's an alternative version using recursion. Also, it accepts an offset itself. (and also it uses stripos instead of strpos, but that's easy to choose) <?php /** * 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); } ?>

« previous php.notes (#172645) next »