note 101329 deleted from function.strpos by danbrown

From: Date: Fri, 10 Dec 2010 17:11:12 +0000
Subject: note 101329 deleted from function.strpos by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-174776@lists.php.net to get a copy of this message
Note Submitter: Anonymous ---- function containsSubstring($haystack, $needle, $matchCase, $pos=-1) { // $pos can be 0 (starting position), 1 (end position) or -1 (any position) if (!$matchCase) { $haystack = strtolower($haystack); $needle = strtolower($needle); } switch ($pos) { case 0: return (strpos($haystack, $needle) === 0); case 1: return (substr($haystack, strlen($haystack) - strlen($needle)) === $needle); case -1: return (strpos($haystack, $needle) !== false); default: return false; } }

« previous php.notes (#174776) next »