如何用PHP遍历文件夹并改写所有文件为长尾?

2026-04-03 14:001阅读0评论SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计146个文字,预计阅读时间需要1分钟。

如何用PHP遍历文件夹并改写所有文件为长尾?

plaintext/** * 遍历文件夹 * @param dir string 文件夹路径 * @param all boolean 是否递归遍历 * @return array 返回文件列表 */public static function scanfDir($dir='', $all=false, &$ret=array()){ if (false !==($handle=opendir($dir))) { while (false !==($entry=readdir($handle))) { if ($entry !=. && $entry !=..) { $fullPath=$dir . DIRECTORY_SEPARATOR . $entry; if ($all || !is_dir($fullPath)) { $ret[]=$fullPath; } if ($all && is_dir($fullPath)) { scanfDir($fullPath, $all, $ret); } } } closedir($handle); }}

/** * 遍历文件夹 * @param string $dir * @param boolean $all true表示递归遍历 * @return array */ public static function scanfDir($dir='', $all = false, &$ret = array()){ if ( false !== ($handle = opendir ( $dir ))) { while ( false !== ($file = readdir ( $handle )) ) { if (!in_array($file, array('.', '..', '.git', '.gitignore', '.svn', '.htaccess', '.buildpath','.project'))) { $cur_path = $dir . '/' . $file; if (is_dir ( $cur_path )) { $ret['dirs'][] =$cur_path; $all && self::scanfDir( $cur_path, $all, $ret); } else { $ret ['files'] [] = $cur_path; } } } closedir ( $handle ); } return $ret; }

如何用PHP遍历文件夹并改写所有文件为长尾?

本文共计146个文字,预计阅读时间需要1分钟。

如何用PHP遍历文件夹并改写所有文件为长尾?

plaintext/** * 遍历文件夹 * @param dir string 文件夹路径 * @param all boolean 是否递归遍历 * @return array 返回文件列表 */public static function scanfDir($dir='', $all=false, &$ret=array()){ if (false !==($handle=opendir($dir))) { while (false !==($entry=readdir($handle))) { if ($entry !=. && $entry !=..) { $fullPath=$dir . DIRECTORY_SEPARATOR . $entry; if ($all || !is_dir($fullPath)) { $ret[]=$fullPath; } if ($all && is_dir($fullPath)) { scanfDir($fullPath, $all, $ret); } } } closedir($handle); }}

/** * 遍历文件夹 * @param string $dir * @param boolean $all true表示递归遍历 * @return array */ public static function scanfDir($dir='', $all = false, &$ret = array()){ if ( false !== ($handle = opendir ( $dir ))) { while ( false !== ($file = readdir ( $handle )) ) { if (!in_array($file, array('.', '..', '.git', '.gitignore', '.svn', '.htaccess', '.buildpath','.project'))) { $cur_path = $dir . '/' . $file; if (is_dir ( $cur_path )) { $ret['dirs'][] =$cur_path; $all && self::scanfDir( $cur_path, $all, $ret); } else { $ret ['files'] [] = $cur_path; } } } closedir ( $handle ); } return $ret; }

如何用PHP遍历文件夹并改写所有文件为长尾?