note 52603 added to function.fnmatch
| From: | jcannonb at gmail dot com | Date: | Fri, 06 May 2005 19:50:14 +0000 |
| Subject: | note 52603 added to function.fnmatch | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-89033@lists.php.net to get a copy of this message | ||
I wrote a better SQL match. The other one had bugs in it:
function sql_match($pattern,$data)
{
$lpattern=strtolower($pattern);
$ldata=strtolower($data);
$lp=strlen($lpattern);
$ld=strlen($ldata);
$ip=0;
$id=0;
for ($ip=0; $ip<$lp; $ip++)
{
if ($lpattern[$ip]=='%')
{
$ip++;
if ($ip >= $lp)
{
return true;
}
for (;;)
{
if ($lpattern[$ip] == $ldata[$id])
{
break;
}
else
{
$id++;
if ($id > $ld)
{
return false;
}
}
}
}
if ($lpattern[$ip] <> $ldata[$id])
{
return false;
}
$id++;
}
if ($ld >= $lp)
{
if ($lpattern[$lp-1] != '%')
{
return false;
}
}
return true;
}
----
Manual Page -- http://www.php.net/manual/en/function.fnmatch.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+52603
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52603&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52603&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52603&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52603&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52603&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+52603&report=yes
Search -- http://master.php.net/manage/user-notes.php