note 99197 added to function.strpos

From: Date: Mon, 02 Aug 2010 18:38:38 +0000
Subject: note 99197 added to function.strpos
Groups: php.notes 
Request: Send a blank email to php-notes+get-171338@lists.php.net to get a copy of this message
Here's my own implementation of a strpos function that allows wildcards in the needle. If the $needle starts with a * and is found to match the $haystack, 0 will be returned. <?php function gh_wild_strpos($haystack, $needle, $offset = 0) { $is_wild = (strpos($needle, "*") !== FALSE); if (!$is_wild) { return strpos($haystack, $needle, $offset); } $haystack = substr($haystack, $offset); $needles = explode("*", $needle); if ($needle[0] == '*') { $first_index = 0; } foreach ($needles as $needle_part) { if ($needle_part == '') { continue; } $needle_index = strpos($haystack, $needle_part); if (!isset($first_index)) { $first_index = $needle_index; } if ($needle_index === FALSE) { return FALSE; } else { $found = TRUE; $haystack = substr($haystack, $needle_index + strlen($needle_part)); } } if ($found) { return $first_index; } return FALSE; } ?> ---- Server IP: 216.235.13.26 Probable Submitter: 70.83.170.102 (proxied: 72.249.190.156) ---- Manual Page -- http://www.php.net/manual/en/function.strpos.php Edit -- https://master.php.net/note/edit/99197 Del: integrated -- https://master.php.net/note/delete/99197/integrated Del: useless -- https://master.php.net/note/delete/99197/useless Del: bad code -- https://master.php.net/note/delete/99197/bad+code Del: spam -- https://master.php.net/note/delete/99197/spam Del: non-english -- https://master.php.net/note/delete/99197/non-english Del: in docs -- https://master.php.net/note/delete/99197/in+docs Del: other reasons-- https://master.php.net/note/delete/99197 Reject -- https://master.php.net/note/reject/99197 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#171338) next »