public static function scan($path, $recursive = true, $excludeDir = true) { $path = self::formatPath($path); $dh = opendir($path); if (!$dh) { return []; } $files = []; while (false !== ($file = readdir($dh))) { if ($file == '.' || $file == '..') { continue; } $fileType = filetype($path . $file); if ('file' == $fileType) { $files[] = $path . $file; } if ('dir' == $fileType) { if (true === $recursive) { $innerFiles = Dir::scan($path . $file . '/', $recursive, $excludeDir); $files = Arr::join($files, $innerFiles); } if (false === $excludeDir) { $files[] = $path . $file . '/'; } } } closedir($dh); return $files; }
// output: This NUMBER word sentence is less than NUMBER letters long. echo $b->replace("/([0-9]+)/", 'NUMBER', true) . "\n"; // not using regular expressions, and lowercase // output: this9wordsentenceislessthan1000letterslong. echo $b->replace(' ', '')->toLower() . "\n"; // something a bit more complex // strips the trailing 0's and 9's and splits it into an array, adds an element, reverse sorts it and turns it into an array // output: /* Array ( [8] => hi there! [7] => 8 [6] => 7 [5] => 6 [4] => 5 [3] => 4 [2] => 3 [1] => 2 [0] => 1 ) */ print_r($a->rtrim('09')->split()->push('hi there!')->rsort()->toArray()); // turning a standard array into a special array $c = new Arr(array('hi', 'there', 'how', 'are', 'you?')); // output: hi there how are you? echo $c->join(' ') . "\n"; // you can still use the String class like an array: $d = new String('012345'); // output: string(1) "3" var_dump($d[3]);