html-minifier
The Blink HTMLTokenizer ported to PHP and minify HTML.
Requirements
Any flavor of PHP 5.3 should do [optional] PHPUnit 3.5+ to execute the test suite (phpunit --version)Use
Create composer.json. [composer.json]
{ "require": { "zaininnari/html-minifier": "*" } }
Download composer.phar and install.
curl -sS https://getcomposer.org/installer | php php composer.phar install
<?php require 'vendor/autoload.php'; use zzHtmlHTMLMinify; $html = '<div> <p> text </p> </div>'; // shortcut. retrun minify html $minify = HTMLMinify::minify($html); // detail $HTMLMinify = new HTMLMinify($html); $minify = $HTMLMinify->process();
output html
<div> <p> text </p> </div>
Option
optimizationLevel
OPTIMIZATION_SIMPLE(default)
Replace many whitespace to a single whitespace. This option leave a new line of one.
[input]
<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>
[output]
<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
Remove the whitespace of all as much as possible.
Remove whitespace between block element and block element between block element and inline element run trim in style, script and downlevel-revealed conditional comment [future] consider comments Preserve whitespace between inline element and inline element[input]
<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>
[output]
<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>
Author
zaininnari
http://www.zay.jp/
Original source
http://www.chromium.org/blink
License
Licensed under the MIT License and other License - see the LICENSE
file for details
版权声明:
1、该文章(资料)来源于互联网公开信息,我方只是对该内容做点评,所分享的下载地址为原作者公开地址。2、网站不提供资料下载,如需下载请到原作者页面进行下载。
3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考学习用!
4、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。