note 52312 deleted from function.fnmatch by victor
| From: | victor@php.net | Date: | Fri, 19 Aug 2005 11:31:31 +0000 |
| Subject: | note 52312 deleted from function.fnmatch by victor | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-93889@lists.php.net to get a copy of this message | ||
Note Submitter: jcannonb at gmail dot com
----
/******************************************************************\
* sql_match Written by Joshua C. Butcher *
* Works like the like() functionality in SQL *
* %zealbot% matches zealbot 1234zealbot and zealbodt1234 *
* zealbot% matches zealbot1234 *
* %zealbot matches 1234zealbot *
* zealbot matches only zealbot *
/******************************************************************/
function sql_match($pattern,$data)
{
$lp=strlen($pattern);
$ld=strlen($data);
$ip=0;
$id=0;
for ($ip=0; $ip<$lp; $ip++)
{
if ($pattern[$ip]=='%')
{
$ip++;
if ($ip >= $lp)
{
return true;
}
for (;;)
{
if ($pattern[$ip] == $data[$id])
{
break;
}
else
{
$id++;
if ($id > $ld)
{
return true;
}
}
}
}
if ($pattern[$ip] <> $data[$id])
{
return false;
}
$id++;
}
if ($ld <> $lp)
{
return false;
}
return true;
}