08c04-1.php
来自「介绍PHP5的给类型函数应用」· PHP 代码 · 共 40 行
PHP
40 行
<?php// A function that will traverse a directory tree, looking for files// that match a given regular expression, and returns all files:function find($regex, $dir) { $matches = array(); // Ok, open up the directory and prepare to start looping: $d = dir($dir); // Loop through all the files: while (false !== ($file = $d->read())) { // Skip . and .., we don't want to deal with them. if (($file == '.') || ($file == '..')) { continue; } // If this is a directory, then: if (is_dir("{$dir}/{$file}")) { // Call this function recursively to look in that subdirectory: $submatches = find($regex, "{$dir}/{$file}"); // Add them to the current match list: $matches = array_merge($matches, $submatches); } else { // It's a file, so check to see if it is a match: if (preg_match($regex, $file)) { // Add it to our array: $matches[] = "{$dir}/{$file}"; } } } // Ok, that's it, return the array now: return $matches;}// Look for all PHP files on your website, starting with the document root:$found = find('/\.php$/', $_SERVER['DOCUMENT_ROOT']);// Sort, then Display them:sort($found);echo '<pre>', print_r($found, true), '</pre>';?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?