note 81395 added to ref.dir

From: Date: Tue, 26 Feb 2008 13:02:57 +0000
Subject: note 81395 added to ref.dir
Groups: php.notes 
Request: Send a blank email to php-notes+get-136494@lists.php.net to get a copy of this message
// Function for searching files recursively using a regex. // $type - array of file types, which will be returned as a result. // $realpath - if set to true, returns absolute paths instead of relative. // Warning: regex is applied to the whole path (not only to file name). <?php function find_regex($path, $regex, $realpath = false, $type = array('file')) { B B $result = array(); B B $realpath && $path = realpath($path); B B if (preg_match($regex, $path) && in_array(@filetype($path), $type)) { B B B B $result[] = $path; B B } B B if ($dh = @opendir($path)) { B B B B while (($obj = readdir($dh)) !== false) { B B B B B B if ($obj == '.' || $obj == '..') continue; B B B B B B $obj = $path . DIRECTORY_SEPARATOR . $obj; B B B B B B $ftype = @filetype($obj); B B B B B B if ($ftype !== 'dir') { B B B B B B B B in_array($ftype, $type) && preg_match($regex, $obj) && $result[] = $obj; B B B B B B } else { B B B B B B B B $result = array_merge($result, find_regex(&$obj, &$regex, &$realpath, &$type)); B B B B B B } B B B B } B B } B B return $result; } ---- Server IP: 195.54.192.44 Probable Submitter: 80.76.129.4 ---- Manual Page -- http://www.php.net/manual/en/ref.dir.php Edit -- https://master.php.net/note/edit/81395 Del: integrated -- https://master.php.net/note/delete/81395/integrated Del: useless -- https://master.php.net/note/delete/81395/useless Del: bad code -- https://master.php.net/note/delete/81395/bad+code Del: spam -- https://master.php.net/note/delete/81395/spam Del: non-english -- https://master.php.net/note/delete/81395/non-english Del: in docs -- https://master.php.net/note/delete/81395/in+docs Del: other reasons-- https://master.php.net/note/delete/81395 Reject -- https://master.php.net/note/reject/81395 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#136494) next »