ListFind / ListFindNoCase

The ListFind and ListFindNoCase are identical functions other than the obvious reason; one is case sensative and the other is not. If you use list to store data or move data, the ListFind function is incredibly useful. Also, the ListFind function works well when rerading comma seperated lists or scraping data from other websites.

The Function:


<?php

function ListFind($list,$value,$delimiter=",")
{
$delimiter = substr($delimiter,1);
$a = explode($delimiter,$list);
for($i=0;$i<count($a);$i++)
{
if( strstr($a[$i],$value))
{
return true ;
}
}
return false;
}

function ListFindNoCase($list,$value,$delimiter=",")
{
$a = explode($delimiter,$list);
for ($i=0;$i<count($a);$i++)
{
if(stristr($a[$i],$value))
{
return true;
}
}
return false;
}


?>

Usage:

<?php
$list = "Car,Truck,Boat,Plane,Train" ;
$find = "car";
if(ListFind($list,$find))
{
echo $find . " found!";
}
?>


Using the ListFind to find 'car' will fail since the ListFind is case sensetive. However, the ListFindNoCase will do the trick!

<?php
$list = "Car,Truck,Boat,Plane,Train" ;
$find = "car";
if( ListFindNoCase($list,$find))
{
echo $find . " found!";
}
?>

The result in this case will be : car found!