tomzx/html-parser 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

tomzx/html-parser

最新稳定版本:v0.1.0

Composer 安装命令:

composer require tomzx/html-parser

包简介

An HTML parser written in PHP

README 文档

README

License Latest Stable Version Latest Unstable Version Build Status Code Quality Code Coverage Total Downloads

An HTML parser written in PHP. Based on nikic's PHP Parser.

Getting started

HTML parser goal is to simplify the traversal/modification of an HTML tree using the visitor pattern.

First, you'll want to parse your HTML using the Parser in order to generate a data structure appropriate for the NodeTraverser. Once that is done, you specify one or many visitors that implement the operation you want to apply on the HTML elements. Then, you traverse the HTML tree structure, which will call the visitors on every element entry/exit. Finally, you may print back the final output as a string.

<?php

$code = file_get_contents('input.html');

$parser = new Parser();
$statements = $parser->parse($code);

$traverser = new NodeTraverser();
$traverser->addVisitor(new ElementStripper(['head', 'a'])); // A visitor which removes any element of a specific type

$statements = $traverser->traverse($statements);

$printer = new Printer();
$printer->output($statements);

License

The code is licensed under the MIT license. See LICENSE.

统计信息

  • 总下载量: 12
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-07-31