note 45088 modified in function.strpos by philip
| From: | philip@php.net | Date: | Fri, 27 Aug 2004 20:25:00 +0000 |
| Subject: | note 45088 modified in function.strpos by philip | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-75459@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 = 0) {
if ($insensitive) {
return (false !== stristr($haystack, $needle)) ? true : false;
} else {
return (false !== strpos($haystack, $needle)) ? true : false;
}
}
?>
--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($needle, $haystack)) ? true : false;
}
}
?>
http://php.net/manual/en/function.strpos.php