note 31353 added to function.fnmatch
| From: | michael at zend dot com | Date: | Fri, 18 Apr 2003 09:18:52 +0000 |
| Subject: | note 31353 added to function.fnmatch | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-46772@lists.php.net to get a copy of this message | ||
Try this one, supporting all filename matching facilities:
// MY_FNMATCH
function my_fnmatch($pattern, $file)
{
for($i=0; $i<strlen($pattern); $i++) {
if($pattern[$i] == "*") {
for($c=$i; $c<max(strlen($pattern), strlen($file)); $c++) {
if(my_fnmatch(substr($pattern, $i+1), substr($file, $c))) {
return true;
}
}
return false;
}
if($pattern[$i] == "[") {
$letter_set = array();
for($c=$i+1; $c<strlen($pattern); $c++) {
if($pattern[$c] != "]") {
array_push($letter_set, $pattern[$c]);
}
else break;
}
foreach ($letter_set as $letter) {
if(my_fnmatch($letter.substr($pattern, $c+1), substr($file, $i))) {
return true;
}
}
return false;
}
if($pattern[$i] == "?") {
continue;
}
if($pattern[$i] != $file[$i]) {
return false;
}
}
return true;
}
--
http://www.php.net/manual/en/function.fnmatch.php
http://master.php.net/manage/user-notes.php?action=edit+31353
http://master.php.net/manage/user-notes.php?action=delete+31353
http://master.php.net/manage/user-notes.php?action=reject+31353