PHPackages                             gclinux/html-parser - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. gclinux/html-parser

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

gclinux/html-parser
===================

Html Parser

v3.0.1(6y ago)63602MITPHPPHP &gt;=5.5

Since Jan 7Pushed 6y agoCompare

[ Source](https://github.com/gclinux/html-parser)[ Packagist](https://packagist.org/packages/gclinux/html-parser)[ Docs](https://github.com/gclinux/html-parser)[ RSS](/packages/gclinux-html-parser/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)Dependencies (1)Versions (7)Used By (0)

HtmlParser
==========

[](#htmlparser)

[![Total Downloads](https://camo.githubusercontent.com/8add814bc613059bd740b45438790eae371909d6e4bd2bb33e730bc79ef43009/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f776e6c6f6164732d392e346b2d677265656e2e737667)](https://packagist.org/packages/gclinux/html-parser)[![Build Status](https://camo.githubusercontent.com/8c8f8584766e75285f93c8797e741fd2b8e3f067a8bc04e37fb4c8c8303070d2/68747470733a2f2f6170692e7472617669732d63692e6f72672f67636c696e75782f68746d6c2d7061727365722e737667)](https://travis-ci.org/gclinux/html-parser)

php html解析工具，类似与PHP Simple HTML DOM Parser。 由于基于php模块dom，所以在解析html时的效率比 PHP Simple HTML DOM Parser 快好几倍。

注意：html代码必须是utf-8编码字符，如果不是请转成utf-8
如果有乱码的问题参考：

现在支持composer

#### *安装*

[](#安装)

命令行下 composer require gclinux/html-parser

加载composer
require 'vendor/autoload.php';

假如你已经使用bupt1987/html-parser 你可以
从 bupt1987/html-parser中升级:
composer remove bupt1987/html-parser
composer require gclinux/html-parser

================================================================================

##### *Example*

[](#example)

```

```

基础用法
====

[](#基础用法)

```
// 查找所有a标签
$ret = $html->find('a');

// 查找a标签的第一个元素
$ret = $html->find('a', 0);

// 查找a标签的倒数第一个元素
$ret = $html->find('a', -1);

// 查找所有含有id属性的div标签
$ret = $html->find('div[id]');

// 查找所有含有id属性为foo的div标签
$ret = $html->find('div[id=foo]');

```

高级用法
====

[](#高级用法)

```
// 查找所有id=foo的元素
$ret = $html->find('#foo');

// 查找所有class=foo的元素
$ret = $html->find('.foo');

// 查找所有拥有 id属性的元素
$ret = $html->find('*[id]');

// 查找所有 anchors 和 images标记
$ret = $html->find('a, img');

// 查找所有有"title"属性的anchors and images
$ret = $html->find('a[title], img[title]');

```

层级选择器
=====

[](#层级选择器)

```
// Find all  in
$es = $html->find('ul li');

// Find Nested  tags
$es = $html->find('div div div');

// Find all  in  which class=hello
$es = $html->find('table.hello td');

// Find all td tags with attribite align=center in table tags
$es = $html->find('table td[align=center]');

```

嵌套选择器
=====

[](#嵌套选择器)

```
// Find all  in
foreach($html->find('ul') as $ul)
{
       foreach($ul->find('li') as $li)
       {
             // do something...
       }
}

// Find first  in first
$e = $html->find('ul', 0)->find('li', 0);

```

属性过滤
====

[](#属性过滤)

```
支持属性选择器操作:

过滤	描述
[attribute]	匹配具有指定属性的元素.
[!attribute]	匹配不具有指定属性的元素。
[attribute=value]	匹配具有指定属性值的元素
[attribute!=value]	匹配不具有指定属性值的元素
[attribute^=value]	匹配具有指定属性值开始的元素
[attribute$=value]	匹配具有指定属性值结束的元素
[attribute*=value]	匹配具有指定属性的元素,且该属性包含了一定的值

```

Dom扩展用法
=======

[](#dom扩展用法)

```
获取dom通过扩展实现更多的功能，详见：http://php.net/manual/zh/book.dom.php

/**
 * @var \DOMNode
 */
$oHtml->node

$oHtml->node->childNodes
$oHtml->node->parentNode
$oHtml->node->firstChild
$oHtml->node->lastChild
等等...

```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 92.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~333 days

Recently: every ~383 days

Total

6

Last Release

2479d ago

Major Versions

v1.1.1 → v2.12015-05-21

v2.2.1 → v3.0.02016-04-21

PHP version history (2 changes)v1.1.1PHP &gt;=5.3.2

v3.0.0PHP &gt;=5.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/6d936ead2ff5263eab7482a3ae58a6ba348bb93f7b9add32e4f4a225161ec95f?d=identicon)[gclinux](/maintainers/gclinux)

---

Top Contributors

[![bupt1987](https://avatars.githubusercontent.com/u/1306979?v=4)](https://github.com/bupt1987 "bupt1987 (96 commits)")[![etaoism](https://avatars.githubusercontent.com/u/58493006?v=4)](https://github.com/etaoism "etaoism (3 commits)")[![gclinux](https://avatars.githubusercontent.com/u/4175914?v=4)](https://github.com/gclinux "gclinux (3 commits)")[![chenjia404](https://avatars.githubusercontent.com/u/2457958?v=4)](https://github.com/chenjia404 "chenjia404 (1 commits)")[![greenjackal](https://avatars.githubusercontent.com/u/43671114?v=4)](https://github.com/greenjackal "greenjackal (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/gclinux-html-parser/health.svg)

```
[![Health](https://phpackages.com/badges/gclinux-html-parser/health.svg)](https://phpackages.com/packages/gclinux-html-parser)
```

###  Alternatives

[mtdowling/jmespath.php

Declaratively specify how to extract elements from a JSON document

2.0k472.8M135](/packages/mtdowling-jmespathphp)[opis/closure

A library that can be used to serialize closures (anonymous functions) and arbitrary data.

2.6k230.0M284](/packages/opis-closure)[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M65](/packages/sabberworm-php-css-parser)[michelf/php-markdown

PHP Markdown

3.5k52.4M345](/packages/michelf-php-markdown)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
