php 去除注释压缩 heredoc去注释不压缩
2015-04-08 16:10
155 查看
<?php header("content-type:text/html;charset=utf-8"); $str = "./hom/ChapterAction.class.php"; file_put_contents("./abc.php",replace_php_src($str)); function replace_php_src($src){ $contents = file_get_contents($src); $num = substr_count($contents,'<<<'); // heredoc 是否存在。 $str = ""; if($num > 0){ // heredoc 存在。只去除注释不压缩。 $file = token_get_all($contents); // token_get_all() 将提供的源码按 PHP 标记进行分割. for ($i=0; $i < count($file); $i++) { if( is_string($file[$i]) ){ $str .= $file[$i]; }else{ $name = token_name( $file[$i][0] ); // token_name() 获取提供的 PHP 解析器代号的符号名称. if($name == 'T_COMMENT' || $name == 'T_DOC_COMMENT' ){ // 去除注释 continue; }else{ $str .= $file[$i][1]; } } } }else{ $str = php_strip_whitespace($src); // 不存在 heredoc 。因为他会错误解析。 } return $str; }
相关文章推荐
- 文件夹 递归 去除PHP注释并压缩
- PHP递归遍历文件夹去除注释并压缩php源代码的方法示例
- php_strip_whitespace 去除php文件空行,注释
- PHP压缩html网页代码(清除空格,换行符,制表符,注释标记)
- PHP统计目录下的文件总数及代码行数(去除注释及空行)
- 去除php注释和去除空格函数分享
- PHP文件去掉PHP注释空格的函数分析(PHP代码压缩)
- PHP压缩html网页代码 : 清除空格,制表符,注释标记
- PHP压缩html网页代码原理(清除空格,换行符,制表符,注释标记)
- 去除php注释和去除空格函数分享
- PHP压缩html网页代码(清除空格,换行符,制表符,注释标记)
- php正则去除网页中所有的html,js,css,注释的实现方法
- PHP文件去掉PHP注释空格的函数(PHP代码压缩)
- PHP压缩html网页代码(清除空格,换行符,制表符,注释标记)
- PHP文件去掉PHP注释空格的函数分析(PHP代码压缩)
- 使用正则去除php代码中的注释方法
- PHP统计目录下的文件总数及代码行数(去除注释及空行)
- PHP统计目录下的文件总数及代码行数(去除注释及空行)
- 正则去除php代码中的注释
- CI框架如何把视图文件压缩输出,得到去除了空格注释的html代码