note 119289 added to function.strpos

From: Date: Thu, 05 May 2016 17:42:46 +0000
Subject: note 119289 added to function.strpos
Groups: php.notes 
Request: Send a blank email to php-notes+get-205430@lists.php.net to get a copy of this message
strpos is great for finding the first occurrence of a string, but what if you want the second? Or third? Easy enough: <?php function strposn($haystack, $needle, $num = 1, $offset = 0) { for ($i = 0; $i < $num, $i++) { $x = strpos($haystack, $needle, $offset); if ($x === false) { return false; } $offset = $x+strlen($needle); } return $x; } ?> ---- Server IP: 72.52.91.14 Probable Submitter: 96.233.109.34 ---- Manual Page -- http://php.net/manual/en/function.strpos.php Edit -- https://master.php.net/note/edit/119289 Del: integrated -- https://master.php.net/note/delete/119289/integrated Del: useless -- https://master.php.net/note/delete/119289/useless Del: bad code -- https://master.php.net/note/delete/119289/bad+code Del: spam -- https://master.php.net/note/delete/119289/spam Del: non-english -- https://master.php.net/note/delete/119289/non-english Del: in docs -- https://master.php.net/note/delete/119289/in+docs Del: other reasons-- https://master.php.net/note/delete/119289 Reject -- https://master.php.net/note/reject/119289 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#205430) next »