PHPackages                             ava239/nokogiri - 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. ava239/nokogiri

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

ava239/nokogiri
===============

fork of HTML Parser at http://github.com/olamedia/nokogiri

2.0.2(2y ago)07MITPHPPHP &gt;=5.0.0

Since Jan 18Pushed 2y agoCompare

[ Source](https://github.com/ava239/nokogiri)[ Packagist](https://packagist.org/packages/ava239/nokogiri)[ Docs](http://github.com/olamedia/nokogiri)[ RSS](/packages/ava239-nokogiri/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

[![PHP Composer](https://github.com/olamedia/nokogiri/workflows/PHP%20Composer/badge.svg?branch=master)](https://github.com/olamedia/nokogiri/workflows/PHP%20Composer/badge.svg?branch=master)

> Attention: New version can break compatibility, in that case use previous version under the v1.0 branch or tag which supports even php 5.4+

> \\nokogiri class is left for compatibility

[In English](README.md) [На русском](README.RU.md)

HTML parser
===========

[](#html-parser)

This library is a fast HTML parser, which can work with invalid code (errors are ignored).
Under the hood is used LibXML.
As the input you can use HTML string in UTF-8 encoding or DOMDocument.
For the querying elements CSS selectors are used, which are transformed to XPath expressions internally.

Usage
=====

[](#usage)

### Loading HTML

[](#loading-html)

> HTML errors are ignored

- From HTML string `$saw = new \nokogiri($html);` `$saw = \nokogiri::fromHtml($html);`
- From DOM elements `$saw = new \nokogiri($dom);` `$saw = \nokogiri::fromDom($dom);`

### get($cssSelector)

[](#getcssselector)

$cssSelector elements have the following format: `tagName[attribute=value]#elementId.className:pseudoSelector(expression)`

```
$saw->get('div > a[rel=bookmark]')->toArray();
```

### toArray()

[](#toarray)

Returns underlying DOM structure as an array.
Values are attributes, text content under `#text` key and child elements under numeric keys

### toXml()

[](#toxml)

Returns HTML string

### getDom() toDom()

[](#getdom-todom)

Returns DOMDocument. Given true as the first argument - can also return DOMNodeList or DOMElement

### Iteration over found elements

[](#iteration-over-found-elements)

```
foreach ($saw->get('#sidebar a.topic') as $link){
    var_dump($link['#text']);
}
```

Implemented selectors
=====================

[](#implemented-selectors)

- tag
- .class
- \#id
- \[attr\]
- \[attr=value\]
- :root
- :empty
- :first-child
- :last-child
- :first-of-type
- :last-of-type
- :only-of-type
- :nth-child(a)
- :nth-child(an+b)
- :nth-child(even/odd)

Requirements
============

[](#requirements)

- DOM
- libxml &gt;=2.9.0
- PHP &gt;= 7.3

License
=======

[](#license)

MIT

What's new
==========

[](#whats-new)

### 2.0.0

[](#200)

- Minimal PHP version 7.3
- Minimal LibXML version 2.9.0
- Complete refactoring
- Partially changed behaviour, can break compatibility
- HTML loading behaviour changed
- Test coverage
- Fixed work of nth-child and other selectors
- Incorrect selectors now throw exceptions
- New selectors added

### 1.0.0

[](#100)

- First version, 2011
- Minimal PHP version 5.4

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 Bus Factor1

Top contributor holds 92.6% 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

Unknown

Total

1

Last Release

846d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/111c53de1db8bfcf869acce973484fe46cafc20de6689012a5be2dc2d204855c?d=identicon)[ava239](/maintainers/ava239)

---

Top Contributors

[![olamedia](https://avatars.githubusercontent.com/u/611624?v=4)](https://github.com/olamedia "olamedia (63 commits)")[![billionaire](https://avatars.githubusercontent.com/u/6255854?v=4)](https://github.com/billionaire "billionaire (2 commits)")[![ava239](https://avatars.githubusercontent.com/u/24976731?v=4)](https://github.com/ava239 "ava239 (1 commits)")[![Niremizov](https://avatars.githubusercontent.com/u/3479186?v=4)](https://github.com/Niremizov "Niremizov (1 commits)")[![positronium](https://avatars.githubusercontent.com/u/5811354?v=4)](https://github.com/positronium "positronium (1 commits)")

---

Tags

parserhtmlparse

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ava239-nokogiri/health.svg)

```
[![Health](https://phpackages.com/badges/ava239-nokogiri/health.svg)](https://phpackages.com/packages/ava239-nokogiri)
```

###  Alternatives

[masterminds/html5

An HTML5 parser and serializer.

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

An HTML DOM parser. It allows you to manipulate HTML. Find tags on an HTML page with selectors just like jQuery.

2.4k7.9M123](/packages/paquettg-php-html-parser)[sunra/php-simple-html-dom-parser

Composer adaptation of: A HTML DOM parser written in PHP5+ let you manipulate HTML in a very easy way! Require PHP 5+. Supports invalid HTML. Find tags on an HTML page with selectors just like jQuery. Extract contents from HTML in a single line.

1.3k9.4M61](/packages/sunra-php-simple-html-dom-parser)[imangazaliev/didom

Simple and fast HTML parser

2.2k2.3M64](/packages/imangazaliev-didom)[olamedia/nokogiri

HTML Parser

23176.3k3](/packages/olamedia-nokogiri)[simplehtmldom/simplehtmldom

A fast, simple and reliable HTML document parser for PHP.

1921.3M14](/packages/simplehtmldom-simplehtmldom)

PHPackages © 2026

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