note 99951 added to function.strpos

From: Date: Thu, 16 Sep 2010 12:54:35 +0000
Subject: note 99951 added to function.strpos
Groups: php.notes 
Request: Send a blank email to php-notes+get-172635@lists.php.net to get a copy of this message
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); } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 64.208.49.60 ---- Manual Page -- http://www.php.net/manual/en/function.strpos.php Edit -- https://master.php.net/note/edit/99951 Del: integrated -- https://master.php.net/note/delete/99951/integrated Del: useless -- https://master.php.net/note/delete/99951/useless Del: bad code -- https://master.php.net/note/delete/99951/bad+code Del: spam -- https://master.php.net/note/delete/99951/spam Del: non-english -- https://master.php.net/note/delete/99951/non-english Del: in docs -- https://master.php.net/note/delete/99951/in+docs Del: other reasons-- https://master.php.net/note/delete/99951 Reject -- https://master.php.net/note/reject/99951 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#172635) next »