PHPackages                             gm314/diavazo - 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. gm314/diavazo

ActiveLibrary

gm314/diavazo
=============

PHP 7 HTML Parser

0.2.1(9y ago)014MITPHPPHP &gt;=7.0.0

Since May 6Pushed 8y agoCompare

[ Source](https://github.com/gperler/diavazo)[ Packagist](https://packagist.org/packages/gm314/diavazo)[ RSS](/packages/gm314-diavazo/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (2)Versions (3)Used By (0)

Diavazo PHP7 HTML Parser
========================

[](#diavazo-php7-html-parser)

Diavazo is a wrapper arround `\DOMDocument` and `\DOMElement`. It adds some useful functionality to search within descendants or query by classes. The `HTMLDocument` class allows to either load a string or a file or url. Some basic search methods are available as well.

For example the method `getElement("p .spanClass b.bClass")` allows to search for elements, classes and a combination of both. The example will find all `` elements, all elements with a the class `spanClass` as well as all ``.

The result of these searches are an array of `HTMLElement` objects. These again allow to query, with the difference that searches are only applied to the their direct descendants.

Installation
============

[](#installation)

```
composer require gm314/diavazo

```

Usage
=====

[](#usage)

```
use Diavazo\HTMLDocument;
$document = new HTMLDocument();

// load file
$document->loadFile("local.html");
$document->loadFile("http://mypage.com/test.html");

// load from string
$document->loadString("");
```

HTMLDocument methods
====================

[](#htmldocument-methods)

```
$document = new HTMLDocument();
$document->loadFile(__DIR__ . "/assets/TableToArrayTest.html");

// get element by id
$table = $document->getElementById("associateArrayTest");

// get element by tag name
$elementList = $document->getElementByTagName("div");

// find all  elements, all elements with the class 'spanClass' and all
$elementList = $document->getElement("p .spanClass b.bClass");

// xpath query
$title = $document->query("/html/head/title");

// get root ()
$root = $document->getRootElement();
```

HTMLElement descendants methods
===============================

[](#htmlelement-descendants-methods)

The HTML Element is result of queries like `getElementById`. Further search methods can be applied on the element. They will search within all descendants.

The method `getDescendantByName("td th")` allows to search for several tags.

```
$document = new HTMLDocument();
$document->loadFile(__DIR__ . "/assets/TableToArrayTest.html");

$table = $document->getElementById("table");

// will return the first tr (Breadth-first search)
$table->getFirstDescendantByName("tr");

// will return all td and th elements
$tdList = $table->getDescendantByName("td th");

// will find all elements that have the class 'active'
$root = $document->getRootElement();
$elementsWithClass = $root->getDescendantWithClassName("active");

// will find all elements that have the class 'myClass' and are td or th elements
$elementsWithClass = $root->getDescendantWithClassName("myClass", "td th");

// will find all elements having only the class 'testClass'
$elementsWithExactClass = $root->getDescendantWithClassNameStrict("testClass");

// will find all elements having only the class 'testClass' and are td or th elements
$elementsWithExactClass = $root->getDescendantWithClassNameStrict("testClass", "td th");

// find all  elements, all elements with the class 'spanClass' and all  that are descendants of #myId
$anyElement = $document-getElementById("myId");
$elementList = $document->getElement("p .spanClass b.bClass");
```

HTMLElement attribute methods
=============================

[](#htmlelement-attribute-methods)

```
$document = new HTMLDocument();
$document->loadFile("myFile.html");

$table = $document->getElementBy("myTable");

// will return null if the attribute does not exist otherwise string
$table->getAttributeValue("align");
```

Table to Array Converter
========================

[](#table-to-array-converter)

Diavazo allows converting a table to an associative or index based array. Associative Array will use the first row for the key attribute.

```
$document = new HTMLDocument();
$document->loadFile("tabletest.html");

$table = $document->getElementById("myTableID");

$arrayConverter = new TableToArrayConverter($table);
$array = $arrayConverter->getAsAssociativeArray();

        Key1
        Key2

        Value 1
        Value 2

    ...

will result in:

$array = [
    [
       "Key1" => "Value 1",
       "Key2" => "Value 2"
    ],
    ...
]
```

Table 2 Array using an extractor
================================

[](#table-2-array-using-an-extractor)

The following examples show how to register an extractor. The closure will be invoked with the table data cell (``) and is expected to return the value that will be added to the array. The following example gets the first `` element and extracts the href attribute

```
$document = $this->getDocument();
$table = $document->getElementById("extractorTest");

$arrayConverter = new TableToArrayConverter($table);
$arrayConverter->registerExtractor("columnName", function (HTMLElement $td) {
    $a = $td->getFirstDescendantByName("a");
    return $a->getAttributeValue("href");
});
$array = $arrayConverter->getAsAssociativeArray();
```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~0 days

Total

2

Last Release

3291d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/201e6d6e88070d43f5dfaf3f9052efa0d2e9703d3cdb529c95029c32f8973ffb?d=identicon)[gperler](/maintainers/gperler)

---

Top Contributors

[![gperler](https://avatars.githubusercontent.com/u/4823172?v=4)](https://github.com/gperler "gperler (17 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/gm314-diavazo/health.svg)

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

PHPackages © 2026

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