note 34769 added to function.fnmatch

From: Date: Wed, 06 Aug 2003 08:59:18 +0000
Subject: note 34769 added to function.fnmatch
Groups: php.notes 
Request: Send a blank email to php-notes+get-53497@lists.php.net to get a copy of this message
you couls also try this function that I wrote before I found fnmatch: function WildToReg($str) { $s = ""; for ($i = 0; $i < strlen($str); $i++) { $c = $str{$i}; if ($c =='?') $s .= '.'; // any character else if ($c == '*') $s .= '.*'; // 0 or more any characters else if ($c == '[' || $c == ']') $s .= $c; // one of characters within [] else $s .= '\\' . $c; } $s = '^' . $s . '$'; //trim redundant ^ or $ //eg ^.*\.txt$ matches exactly the same as \.txt$ if (substr($s,0,3) == "^.*") $s = substr($s,3); if (substr($s,-3,3) == ".*$") $s = substr($s,0,-3); return $s; } if (ereg(WildToReg("*.txt"), $fn)) print "$fn is a text file"; else print "$fn is not a text file"; ---- Manual Page -- http://www.php.net/manual/en/function.fnmatch.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34769 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34769&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34769&report=yes

« previous php.notes (#53497) next »