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.

Related articles

No comments

There are still no comments on this article.

Leave your comment...

If you want to leave your comment on this article, simply fill out the next form:




You can use these XHTML tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong> .