note 81396 added to ref.dir

From: Date: Tue, 26 Feb 2008 13:05:33 +0000
Subject: note 81396 added to ref.dir
Groups: php.notes 
Request: Send a blank email to php-notes+get-136495@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')) {     $result = array();     $realpath && $path = realpath($path);     if (preg_match($regex, $path) && in_array(@filetype($path), $type)) {         $result[] = $path;     }     if ($dh = @opendir($path)) {         while (($obj = readdir($dh)) !== false) {             if ($obj == '.' || $obj == '..') continue;             $obj = $path . DIRECTORY_SEPARATOR . $obj;             $ftype = @filetype($obj);             if ($ftype !== 'dir') {                 in_array($ftype, $type) && preg_match($regex, $obj) && $result[] = $obj;             } else {                 $result = array_merge($result, find_regex(&$obj, &$regex, &$realpath, &$type));             }         }     }     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/81396 Del: integrated -- https://master.php.net/note/delete/81396/integrated Del: useless -- https://master.php.net/note/delete/81396/useless Del: bad code -- https://master.php.net/note/delete/81396/bad+code Del: spam -- https://master.php.net/note/delete/81396/spam Del: non-english -- https://master.php.net/note/delete/81396/non-english Del: in docs -- https://master.php.net/note/delete/81396/in+docs Del: other reasons-- https://master.php.net/note/delete/81396 Reject -- https://master.php.net/note/reject/81396 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#136495) next »