note 45088 modified in function.strpos by levim

From: Date: Fri, 06 Dec 2013 16:40:42 +0000
Subject: note 45088 modified in function.strpos by levim
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-197815@lists.php.net to get a copy of this message
Many people look for in_string which does not exist in PHP, so, here's the most efficient form of in_string() (that works in both PHP 4/5) that I can think of: <?php function in_string($needle, $haystack, $insensitive = false) { if ($insensitive) { return false !== stristr($haystack, $needle); } else { return false !== strpos($haystack, $needle); } } ?> --was-- Many people look for in_string which does not exist in PHP, so, here's the most efficient form of in_string() (that works in both PHP 4/5) that I can think of: <?php function in_string($needle, $haystack, $insensitive = 0) { if ($insensitive) { return (false !== stristr($haystack, $needle)) ? true : false; } else { return (false !== strpos($haystack, $needle)) ? true : false; } } ?> http://php.net/manual/en/function.strpos.php

« previous php.notes (#197815) next »