最近想研究一个cms的代码,想把代码转换成文本格式放到手机中看,太多文件不想去改后缀,所以自己就写了一个脚本,很简单,贴出来分享一下
function php2txt($dir){
$items = scandir($dir) ;
foreach ($items as $item){
if ($item=='.' || $item=='..'){
continue;
}
$path = $dir.'/'.$item ;
echo "<br>";
if (is_dir($path)){
php2txt($path);
continue;
}elseif (is_file($path)){
$extArr = array(".php" , ".sql" ,".tpl") ;
$newfile = str_replace($extArr, ".txt", $path);
if (preg_match("/.*(.php|.sql|.tpl)/", $path)){
$content = file_get_contents($path);
file_put_contents($newfile, $content);
ob_flush();
flush();
unlink($path);
}
}
}
}
$dir = "d:/cms";
php2txt($dir);