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!
Blogger templates
Blogger news
Blogroll
Archives
-
▼
2011
(212)
-
▼
February
(21)
- Datos Enteros en Php
- Resize images on the fly in PHP
- Variables in PHP
- Create Sidebar using PHP and Dreamweaver
- PHP Code :- How to avoid Word breaking while we ar...
- Store and saving binary data (images, coding, etc....
- Boolean data type
- For creating zip file in php for the contents in a...
- Finding root parent of a child category in php
- array() in php
- getcwd() and chdir() in php
- Best & Popular PHP Frameworks
- ListFind / ListFindNoCase
- instant5dollars
- MYSQL String functions makes life easier
- acessing xml in php sent by other script
- Mengambil Pola Teks
- No title
- compound data types in php
- open files in a directory with dir() in php
- Php ini settings for large file uploads.
-
▼
February
(21)