raivisdejus / html-minifier
将 Blink HTMLTokenizer 移植到 PHP。
0.5.0
2018-06-11 06:36 UTC
Requires
- php: >=5.3.0
Requires (Dev)
- satooshi/php-coveralls: v2.0.0
This package is not auto-updated.
Last update: 2024-09-26 08:41:36 UTC
README
将 Blink HTMLTokenizer 移植到 PHP 并压缩 HTML。
要求
- 任何 PHP 5.3 版本都应适用
- [可选] 使用 PHPUnit 3.5+ 执行测试套件(phpunit --version)
使用方法
创建 composer.json 文件。[composer.json]
{ "require": { "raivisdejus/html-minifier": "*" } }
下载 composer.phar 并安装。
curl -sS https://getcomposer.org/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
文件