PHPackages                             atrox/matcher - 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. atrox/matcher

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

atrox/matcher
=============

Powerful XML and HTML matching and data extraction library

v1.1.1(8y ago)9498.1k↓44.9%8[2 PRs](https://github.com/kaja47/Matcher/pulls)3BSD-3-ClausePHPPHP &gt;=5.3.0

Since Jun 19Pushed 6y ago12 watchersCompare

[ Source](https://github.com/kaja47/Matcher)[ Packagist](https://packagist.org/packages/atrox/matcher)[ RSS](/packages/atrox-matcher/feed)WikiDiscussions master Synced 1mo ago

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

Atrox\\Matcher
==============

[](#atroxmatcher)

[![Downloads this Month](https://camo.githubusercontent.com/8b64462d2c666a702c12edb52df4e5bc14755b53611c05c1066fe3369d0997e2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6174726f782f6d6174636865722e737667)](https://packagist.org/packages/atrox/matcher)[![Build Status](https://camo.githubusercontent.com/8dbb06eadcd8b5639ef403d3c8d2df46990a085e091c5e2c164b2db97d4acd3f/68747470733a2f2f7472617669732d63692e6f72672f6b616a6134372f4d6174636865722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/kaja47/Matcher)[![License](https://camo.githubusercontent.com/7cdfddcf4df739bc97b826685cfeddab3a7515337392bc317bd8ed9f5a87c983/68747470733a2f2f706f7365722e707567782e6f72672f6174726f782f4d6174636865722f6c6963656e73652e737667)](https://packagist.org/packages/atrox/Matcher)

Matcher - powerful tool for extracting data from XML and HTML using [XPath](https://en.wikipedia.org/wiki/XPath) and pure magic.

[Why was Matcher made (czech)](https://funkcionalne.k47.cz/2014/05/php-dom-simplexml-a-matcher.html), [XPath intro (czech)](https://funkcionalne.k47.cz/2015/01/xpath-co-proc-a-hlavne-jak.html)

Installation:
-------------

[](#installation)

Install Matcher using [Composer](https://getcomposer.org/):

```
composer require atrox/matcher

```

Examples:
---------

[](#examples)

```
use Atrox\Matcher;

$m = Matcher::multi('//div[@id="siteTable"]/div[contains(@class, "thing")]', [
  'id'    => '@data-fullname',
  'title' => './/p[@class="title"]/a',
  'url'   => './/p[@class="title"]/a/@href',
  'date'  => './/time/@datetime',
  'img'   => 'a[contains(@class, "thumbnail")]/img/@src',
  'votes' => (object) [
    'ups'   => '@data-ups',
    'downs' => '@data-downs',
    'rank'  => 'span[@class="rank"]',
    'score' => './/div[contains(@class, "score")]',
  ],
])->fromHtml();

$f = file_get_contents('http://www.reddit.com/');

$extractedData = $m($f);
```

result:

```
[
  [
    "id"    => "t3_1ep0c5",
    "title" => "Obligatory funny cat pictures.",
    "url"   => "http://imgur.com/sGu0pEk",
    "date"  => "2013-05-20T14:16:24+00:00",
    "img"   => "http://e.thumbs.redditmedia.com/MZjtg3UnZ8MOVjcd.jpg",
    "votes" => (object) [
      "ups"   => "115036",
      "downs" => "10266",
      "rank"  => "1",
      "score" => "105650"
    ]
  ],
  [
    ...
  ]
]
```

---

Matchers can be arbitrarily chained and nested.

```
$postMatcher = Matcher::single('.//div[@class="postInfo desktop"]', [
  'id'   => './input/@name',
  'name' => './span[@class="nameBlock"]/span[@class="name"]',
  'date' => './span/@data-utc',
]);

$m = Matcher::multi('//div[@class="thread"]', [
  'op'      => Matcher::single('./div[@class="postContainer opContainer"]', $postMatcher),
  'replies' => Matcher::multi('./div[@class="postContainer replyContainer"]', $postMatcher)
])->fromHtml();

$f = file_get_contents('http://boards.4chan.org/po/');

$extractedData = $m($f);
```

result:

```
[
  [
    "op" => [
      "id"   => "481874858",
      "name" => "Anonymous",
      "date" => "1369242761"
    ],
    "replies" => [
      [
        "id"   => "481879347",
        "name" => "moot",
        "date" => "1369244554"
      ],
      ...
    ]
  ],
  [
    ...
  ],
  ...
]
```

Use with external parsers:
--------------------------

[](#use-with-external-parsers)

Because Matcher is internally working with [DOMDocument](http://php.net/manual/en/class.domdocument.php) or [SimpleXML](http://php.net/manual/en/book.simplexml.php) objects it's possible to use it with external HTML/XML parsers such as [html5-php](https://github.com/Masterminds/html5-php).

```
$html5 = new Masterminds\HTML5(['disable_html_ns' => true]);
$dom = $html5->loadHTML($html);

$m = Matcher::single('//h1');
$title = $m($dom);
```

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity45

Moderate usage in the ecosystem

Community21

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 56% 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 ~666 days

Total

3

Last Release

3019d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/edb52a1545e7beece69a296777d9d2d5b5c48a67649a7d17b79f7cf4c94aaf73?d=identicon)[kaja47](/maintainers/kaja47)

---

Top Contributors

[![grogy](https://avatars.githubusercontent.com/u/1322983?v=4)](https://github.com/grogy "grogy (14 commits)")[![kaja47](https://avatars.githubusercontent.com/u/127853?v=4)](https://github.com/kaja47 "kaja47 (11 commits)")

---

Tags

xmlhtmlXpath

### Embed Badge

![Health badge](/badges/atrox-matcher/health.svg)

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

###  Alternatives

[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[imangazaliev/didom

Simple and fast HTML parser

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

HTML/XML querying and processing (like jQuery)

8197.0M27](/packages/querypath-querypath)[veewee/xml

XML without worries

1835.9M29](/packages/veewee-xml)[fluentdom/fluentdom

A fluent api for the php dom extension.

337306.9k17](/packages/fluentdom-fluentdom)[rumenx/php-sitemap

Framework-agnostic Sitemap generator for PHP, Laravel, and Symfony.

1.3k15.1k1](/packages/rumenx-php-sitemap)

PHPackages © 2026

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