note 55126 added to function.fnmatch

From: Date: Tue, 26 Jul 2005 11:07:49 +0000
Subject: note 55126 added to function.fnmatch
Groups: php.notes 
Request: Send a blank email to php-notes+get-92459@lists.php.net to get a copy of this message
A "fnmatch" alternative that converts the pattern, to a valid preg one and uses preg_match then. It will work on windows. <?php if (!function_exists('fnmatch')) { function fnmatch($pattern, $string) { for ($op = 0, $npattern = '', $n = 0, $l = strlen($pattern); $n < $l; $n++) { switch ($c = $pattern[$n]) { case '\\': $npattern .= '\\' . @$pattern[++$n]; break; case '.': case '+': case '^': case '$': case '(': case ')': case '{': case '}': case '=': case '!': case '<': case '>': case '|': $npattern .= '\\' . $c; break; case '?': case '*': $npattern .= '.' . $c; break; case '[': case ']': default: $npattern .= $c; if ($c == '[') { $op++; } else if ($c == ']') { if ($op == 0) return false; $op--; } break; } } if ($op != 0) return false; return preg_match('/' . $npattern . '/i', $string); } } ?> ---- Manual Page -- http://www.php.net/manual/en/function.fnmatch.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+55126 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55126&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55126&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55126&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55126&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55126&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55126&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+55126&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#92459) next »