<?php
function stripCommentAndWhitespace($path = '')
{
if (empty($path)) {
echo '请指定要操作的文件路径';
return false;
} else {
$path = str_replace('\\', '/', $path);
}
if ( $handle = opendir ( $path )) {
while ( false !== ( $fileName = readdir ( $handle ))) {
if ( $fileName != "." && $fileName != ".." ) {
if (is_file($path . '/' . $fileName)) {
// 压缩.php后缀文件
$suffix = pathinfo($path . '/' . $fileName, PATHINFO_EXTENSION);
if ($suffix == 'php') {
$newFile = php_strip_whitespace($path . '/'. $fileName);
file_put_contents($path . '/'. $fileName, $newFile);
}
}
if (is_dir($path . '/' . $fileName)) {
stripCommentAndWhitespace($path . '/' . $fileName);
}
}
}
closedir ( $handle );
}
}
stripCommentAndWhitespace('YourProjectNamePath');
?>