note 81394 added to ref.dir
| From: | eeccho at osu1 dot php dot net | Date: | Tue, 26 Feb 2008 13:01:40 +0000 |
| Subject: | note 81394 added to ref.dir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-136493@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/81394
Del: integrated -- https://master.php.net/note/delete/81394/integrated
Del: useless -- https://master.php.net/note/delete/81394/useless
Del: bad code -- https://master.php.net/note/delete/81394/bad+code
Del: spam -- https://master.php.net/note/delete/81394/spam
Del: non-english -- https://master.php.net/note/delete/81394/non-english
Del: in docs -- https://master.php.net/note/delete/81394/in+docs
Del: other reasons-- https://master.php.net/note/delete/81394
Reject -- https://master.php.net/note/reject/81394
Search -- https://master.php.net/manage/user-notes.php