定制 hexydec/htmldoc 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

hexydec/htmldoc

Composer 安装命令:

composer require hexydec/htmldoc

包简介

A token based HTML document parser and minifier. Minify HTML documents including inline CSS, Javascript, and SVG's on the fly. Extract document text, attributes, and fragments. Full test suite.

README 文档

README

A tokeniser based HTML document parser and minifier, written in PHP.

Licence Status: Stable Tests Status Code Coverage

Description

An HTML parser, primarily designed for minifying HTML documents, it also enables the document structure to be queried allowing attribute and textnode values to be extracted.

The parser is designed around a tokeniser to make the document processing more reliable than regex based minifiers, which are a bit blunt and can be problematic if they match patterns in the wrong places.

The software is also capable of processing and minifying SVG documents.

Usage

To minify an HTML document:

use hexydec\html\htmldoc;

$doc = new htmldoc();

// load from a variable
if ($doc->load($html) {

	// minify the document
	$doc->minify();

	// compile back to HTML
	echo $doc->save();
}

You can test out the minifier online at https://hexydec.com/apps/minify-html/, or run the supplied index.php file after installation.

To extract data from an HTML document:

use hexydec\html\htmldoc;

$doc = new htmldoc();

// load from a URL this time
if ($doc->open($url) {

	// extract text
	$text = $doc->find('.article__body')->text();

	// extract attribute
	$attr = $doc->find('.article__author-image')->attr('src');

	// extract HTML
	$html = $doc->find('.article__body')->html();
}

Installation

The easiest way to get up and running is to use composer:

$ composer install hexydec/htmldoc

HTMLdoc requires \hexydec\token\tokenise to run, which you can install manually if not using composer. Optionally you can also install CSSdoc and JSlite to perform inline CSS and Javascript minification respectively.

All these dependencies will be installed through composer.

Test Suite

You can run the test suite like this:

Linux

$ vendor/bin/phpunit

Windows

> vendor\bin\phpunit

Documentation

Support

HTMLdoc supports PHP version 8.0+.

Contributing

If you find an issue with HTMLdoc, please create an issue in the tracker.

If you wish to fix an issue yourself, please fork the code, fix the issue, then create a pull request, and I will evaluate your submission.

Licence

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 11.11k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 26
  • 点击次数: 3
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 26
  • Watchers: 3
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-09-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固