note 119289 deleted from function.strpos by cmb

From: Date: Sun, 02 Jun 2019 09:01:24 +0000
Subject: note 119289 deleted from function.strpos by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-211176@lists.php.net to get a copy of this message
Note Submitter: tuxedobob ---- 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; } ?>

« previous php.notes (#211176) next »