<?php
$path='D:/wamp/www/DolrPHP/Smarty';
function loseWeight($path){
$handle=opendir($path);
readdir($handle);//.
readdir($handle);//..
while($file=readdir($handle)){
$newPath=$path.'/'.$file;
if(is_dir($newPath))
loseWeight($newPath);
else{
//去掉注释行---
$content=file_get_contents($newPath);
$mode=array('/\/\*\*?(.*?)\*\//is','/^\s*$/iU');
$newContent=preg_replace($mode,"",$content);
file_put_contents($newPath,$newContent);
//-----
// 去掉空白行
$content='';
$fp=fopen($newPath,'r');
while(!feof($fp)){
$line=trim(fgets($fp));
if(strlen($line)<=0){
continue;
}
$content.=$line."\n";
}
file_put_contents($newPath,$content);
echo '文件'.$newPath.'瘦身完成!<br />';
}
}
}
show($path);
收藏
最新推荐文章于 2024-08-26 14:28:57 发布