note 31253 added to function.fnmatch
| From: | me at lejfdiecks dot de | Date: | Tue, 15 Apr 2003 12:46:50 +0000 |
| Subject: | note 31253 added to function.fnmatch | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-46641@lists.php.net to get a copy of this message | ||
I had the same problem ("Call to undefined function: fnmatch()") using PHP 4.2.3 on a
hosted webserver; so I wrote "my own" fnmatch(). Hope it helps someone:
function fnmatch($strPattern, $strString)
// My fnmatch()
// Supports '?' and '*' as wildcards
{
$intPos = 0;
do
{
$strPatternChar = substr($strPattern, $intPos, 1);
$strStringChar = substr($strString, $intPos, 1);
if ($strPatternChar == '*')
{
$bolMatch = TRUE;
break;
}
$bolMatch = ($strPatternChar == $strStringChar) || ($strPatternChar == '?' &&
$strStringChar != '');
$intPos++;
} while (($bolMatch == TRUE) && ($intPos < max(strlen($strPattern),
strlen($strString))));
return($bolMatch);
}
// Main program - test fnmatch() function
if (fnmatch('te?t', 'test'))
echo "Pattern <b>matches</b> string.";
else
echo "Pattern <b>does not</b> match string.";
--
http://www.php.net/manual/en/function.fnmatch.php
http://master.php.net/manage/user-notes.php?action=edit+31253
http://master.php.net/manage/user-notes.php?action=delete+31253
http://master.php.net/manage/user-notes.php?action=reject+31253