会员注册关闭
php压缩html 清换行符制表符去注释标记技巧
作者:未知来源:网络收集
整理日期:2019-09-19
php 代码复制内容到剪贴板
- /**
- * 压缩html : 清除换行符,清除制表符,去掉注释标记
- * @param $string
- * @return 压缩后的$string
- * */
- function compress_html($string) {
- $string = str_replace("rn", '', $string); //清除换行符
- $string = str_replace("n", '', $string); //清除换行符
- $string = str_replace("t", '', $string); //清除制表符
- $pattern = array (
- "/> *([^ ]*) *</", //去掉注释标记
- "/[s]+/",
- "/<!--[^!]*-->/",
- "/" /",
- "/ "/",
- "'/*[^*]**/'"
- );
- $replace = array (
- ">\1<",
- " ",
- "",
- """,
- """,
- ""
- );
- return preg_replace($pattern, $replace, $string);
- }
责任编辑: webmaster >>> 百度上搜索 谷歌上搜索
点击复制本连接 (http://www.hugesky.com/showarticle.php?id=6897)>>> 相关资讯:
【声明】: 以上文章或资料除注明为电脑技巧原创或编辑整理外,均为网络收集整理或网友推荐。以上内容以共享、参考、研究为目的,不存在任何商业目的。 未注明作者或出处的文章,可能资料来源不规范。如有涉及版权请给予及时联系更正或予以删除。 |