note 63908 added to function.glob

From: Date: Mon, 03 Apr 2006 15:51:37 +0000
Subject: note 63908 added to function.glob
Groups: php.notes 
Request: Send a blank email to php-notes+get-107233@lists.php.net to get a copy of this message
Case insensitive version of this function for mswin: // only supported flags are GLOB_NOSORT | GLOB_ONLYDIR function iglob($pattern, $flags) { $path = preg_split( '#(?<=\A|[\\\\/])((?>[^\\\\/*?]*)[*?](?>[^\\\\/]*))(?=\Z|[\\\\/])#', $pattern, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY ); foreach ($path as &$n) if (preg_match('/[*?]/', $n)) { $re = ''; for ($i = 0, $l = strlen($n); $i < $l; $i++) switch($n{$i}) { case '*': $re .= '.*'; break; case '?': $re .= '.'; break; default: $re .= sprintf('\x%02x', ord($n{$i})); } $n = array(0, "/^$re$/i"); } else $n = array(1, $n); $res = array(); iglob_DFS($path, $flags, '', 0, $res); if (!($flags & GLOB_NOSORT)) sort($res); return $res; } function iglob_DFS($path, $flags, $parent, $lvl, &$res) { $depth = count($path) - 1; if (($lvl < $depth) && $path[$lvl][0]) $parent .= $path[$lvl++][1]; $files = array(); if ($path[$lvl][0]) $files[] = $path[$lvl][1]; else if ($d = @opendir(($parent == '') ? '.' : $parent)) { while (($n = readdir($d)) !== false) if ($n != '.' && $n != '..') $files[] = $n; closedir($d); } foreach ($files as $f) if ($path[$lvl][0] || preg_match($path[$lvl][1], $f)) { $fullpath = $parent.$f; if ($lvl == $depth) { if (!($flags & GLOB_ONLYDIR) || is_dir($fullpath)) $res[] = $fullpath; } else iglob_DFS($path, $flags, $fullpath, $lvl + 1, $res); } } ---- Server IP: 66.163.161.117 Probable Submitter: 202.72.241.239 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.glob.php Edit -- http://master.php.net/note/edit/63908 Del: integrated -- http://master.php.net/note/delete/63908/integrated Del: useless -- http://master.php.net/note/delete/63908/useless Del: bad code -- http://master.php.net/note/delete/63908/bad+code Del: spam -- http://master.php.net/note/delete/63908/spam Del: non-english -- http://master.php.net/note/delete/63908/non-english Del: in docs -- http://master.php.net/note/delete/63908/in+docs Del: other reasons-- http://master.php.net/note/delete/63908 Reject -- http://master.php.net/note/reject/63908 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#107233) next »