PHP代码加密 — php_strip_whitespace函数,去掉源代码所有注释和空格并展现在一行

<?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’);

?>

相关文章