String IndexOf Case in-sensitive search - PHP
PHP supports a function “strpos” which return the position index of the element found or a false if the element is not found.
Usage
$content = ‘ Search for a string here…’;
$find = ’search’;//lower case s
$pos =strpos($content, $pos);
now $pos will hold a value false;
For case in-sensitive searches, PHP version >5 supports a function “stripos” which return the position index of the element found or a false if the element is not found; Lower versions of the PHP can use the following code to achieve the same functionality
if (!function_exists(”stripos”)) {
function stripos($str,$needle) {
return strpos(strtolower($str),strtolower($needle));
}
}
Written by Ravi Nallakukkala on June 4th, 2007 with no comments.
Read more articles on Uncategorized.