时间:2021-07-01 10:21:17 帮助过:36人阅读
=====================================================
应用 部分
set_time_limit(0);
require 'DirTree.php';
class Gbk2Utf8Action implements DirAction
{
public function doAction($args)
{
$aimPath = ereg_replace('D:/html/web','D:/back', $args);
if ( is_file($args) )
{
$file = implode ('', file($args));
$content = iconv("gb2312", "UTF-8", $file);
$fh = fopen($aimPath, 'w');
fwrite($fh, $content);
fclose($fh);
}
else
{
mkdir($aimPath);
}
}
}
class HtmlPhpFilter implements DirFilter
{
public function doFilter($args)
{
$suffix = substr(strrchr($args, '.'), 1);
if ( ('htm' == $suffix) || ('php' == $suffix) )
return false;
else if ( is_dir($args) )
return false;
else
return true;
}
}
$dirTree = new DirTree();
$action = new Gbk2Utf8Action();
$filter = new HtmlPhpFilter();
$dirTree->setFilter($filter);
$dirTree->listDirFile('D:/html/web', $action);