axy/min-html
最新稳定版本:0.1.1
Composer 安装命令:
composer require axy/min-html
包简介
Compress HTML
关键字:
README 文档
README
Compress HTML.
- The library does not require any dependencies.
- Tested on PHP 5.4+, PHP 7, HHVM (on Linux), PHP 5.5 (on Windows).
- Install:
composer require axy/min-html. - License: MIT.
Compression
Simply removes the indentation at the beginning and end of lines. With some exceptions:
- Indents inside some tags (as
<pre>and<textarea>) are relevant. - The content of some tags can be handled in a special way (compress for
<script>and<style>for example).
Example
The source content:
<head> <title>Test</title> <script> var x = 2 + 2; console.log(x); </script> </head> <body> <h1>Test</h1> <p> This is example of HTML compression. </p> <pre> Content of PRE is PRE </pre> </body>
The compressed content:
<head> <title>Test</title> <script>var x=2+2;console.log(x);</script> </head> <body> <h1>Test</h1> <p> This is example of HTML compression. </p> <pre> Content of PRE is PRE </pre> </body>
API
The library defines the single public class axy\min\html\HTMLMinifier.
Methods:
__construct(string $content [, array $tags])run(void): stringgetOriginContent(void): stringgetCompressedContent(void): stringgetTags(void): array
Static methods:
compress(string $content [, array $tags]): stringcompressFromFile(string $content [, array $tags]): stringcompressFile(string $source, string $destination [, array $tags]): stringgetDefaultsTags([array $tags]): array
Example
Using static:
use axy\min\html\HTMLMinifier; $source = 'index.html'; $destination = 'index.min.html'; HTMLMinifier::compressFile($source, $destination);
Without static:
$min = new HTMLMinifier($content); $min->run(); echo $min->getCompressedContent();
Tags
The optional array tags specifies how to handle content of the tags.
Defaults is
[
'pre' => true,
'textarea' => true,
]
Argument $tags merges with the defaults.
TRUE - do not change.
Or callback.
$tags = [ 'script' => function ($content) { return JSMinify::minify($content); }, 'textarea' => null, // Remove rule for TEXTAREA 'style' => true, // Content of STYLE does not change ]; HTMLMinifier::compressFile($source, $destination, $tags);
统计信息
- 总下载量: 22
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-10-24