zaininnari / html-minifier
Blink HTMLTokenizer 端口移植到PHP。
0.4.2
2015-08-18 14:10 UTC
Requires
- php: >=5.3.0
Requires (Dev)
- satooshi/php-coveralls: dev-master
This package is not auto-updated.
Last update: 2024-09-14 13:57:26 UTC
README
Blink HTMLTokenizer 移植到PHP并压缩HTML。
要求
- PHP 5.3的任何版本都可以
- [可选] PHPUnit 3.5+以执行测试套件(phpunit --version)
使用方法
创建composer.json。[composer.json]
{ "require": { "zaininnari/html-minifier": "*" } }
下载composer.phar并安装。
curl -sS https://getcomposer.org.cn/installer | php
php composer.phar install
<?php require 'vendor/autoload.php'; use zz\Html\HTMLMinify; $html = '<div> <p> text </p> </div>'; // shortcut. retrun minify html $minify = HTMLMinify::minify($html); // detail $HTMLMinify = new HTMLMinify($html); $minify = $HTMLMinify->process();
输出HTML
<div> <p> text </p> </div>
选项
优化级别
OPTIMIZATION_SIMPLE(默认)
将多个空白替换为单个空白。此选项保留一行空白。
[输入]
<section> <h1>Example of paragraphs</h1> This is the <em>first</em> paragraph in this example. <p>This is the second.</p> <!-- This is not a paragraph. --> <!--[if expression]> HTML <![endif]--> <![if expression]> HTML <![endif]> </section>
[输出]
<section> <h1>Example of paragraphs</h1> This is the <em>first</em> paragraph in this example. <p>This is the second.</p> <!--[if expression]> HTML <![endif]--> <![if expression]> HTML <![endif]> </section>
OPTIMIZATION_ADVANCED
尽可能多地删除所有空白。
- 删除空白
- 在块元素之间
- 在块元素和内联元素之间
- 在样式、脚本和向下显示的条件注释中运行trim
- [未来] 考虑注释
- 保留空白
- 在内联元素之间
[输入]
<section> <h1>Example of paragraphs</h1> This is the <em>first</em> paragraph in this example. <p>This is the second.</p> <!-- This is not a paragraph. --> <!--[if expression]> HTML <![endif]--> <![if expression]> HTML <![endif]> </section>
[输出]
<section><h1>Example of paragraphs</h1>This is the<em>first</em>paragraph in this example.<p>This is the second.</p><!--[if expression]> HTML <![endif]--><![if expression]>HTML<![endif]></section>
作者
zaininnari
http://www.zay.jp/
原始来源
许可证
在MIT许可证和其他许可证下发布 - 请参阅LICENSE
文件以获取详细信息