PHPackages                             algolia/php-dom-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. [Search &amp; Filtering](/categories/search)
4. /
5. algolia/php-dom-parser

ActiveLibrary[Search &amp; Filtering](/categories/search)

algolia/php-dom-parser
======================

A simple tool to turn DOM into Algolia search friendly record objects.

0.7.0(3y ago)181.7k6[1 issues](https://github.com/algolia/php-dom-parser/issues)MITPHPPHP &gt;=5.6

Since May 21Pushed 3y ago67 watchersCompare

[ Source](https://github.com/algolia/php-dom-parser)[ Packagist](https://packagist.org/packages/algolia/php-dom-parser)[ Docs](https://github.com/algolia/php-dom-parser)[ RSS](/packages/algolia-php-dom-parser/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (10)Dependencies (2)Versions (12)Used By (0)

[![Build Status](https://camo.githubusercontent.com/0c476839e46ceef6cbcf513d981e9b3e1ee50a53540806e9d05cf1b89ce25873/68747470733a2f2f7472617669732d63692e6f72672f616c676f6c69612f7068702d646f6d2d7061727365722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/algolia/php-dom-parser)

A simple tool to turn DOM into Algolia search friendly record objects.

It has been built with Wordpress articles indexing in mind, but the tool is now abstracted enough to be re-used on other type of projects.

For now the parsed DOM will result in the minimum possible number of records, meaning that if a node has at least one child, it will never have a record on its own. If we need such a behaviour, we could easily add it.

Requirements
------------

[](#requirements)

This lib needs `mbstring` PHP extension to be enabled. Also make sure `mbregex` is **NOT** disabled.

Installation
------------

[](#installation)

```
$ composer require algolia/php-dom-parser

```

Examples
--------

[](#examples)

### Simple usage

[](#simple-usage)

Here is a simple example where we grab the content of an article of Algolia's blog and parse it to obtain the records.

```
$article = file_get_contents('https://blog.algolia.com/how-we-re-invented-our-office-space-in-paris/');

$parser = new \Algolia\DOMParser();

// Exclude content by CSS selectors.
$parser->setExcludeSelectors(array(
    'pre',
    '.entry-meta',
    'div.rp4wp-related-posts'
));

// Only parse what is inside a given CSS selectors.
// If there are multiple nodes matching, they will all be parsed.
$parser->setRootSelector('article.post');

// Define your attributes sibling.
$parser->setAttributeSelectors(
	array(
        'title1'  => 'h1',
        'title2'  => 'h2',
        'title3'  => 'h3',
        'title4'  => 'h4',
        'title5'  => 'h5',
        'title6'  => 'h6',
        'content' => 'p, ul, ol, dl, table',
    )
);

// Add some attributes that will be part of every record.
$parser->setSharedAttributes(array(
    'url'    => 'http://www.example.com',
    'visits' => 1933,
));

// Turn the DOM into Algolia search friendly records.
$records = $parser->parse($article);

var_dump($records);
```

You will find some example of scripts / outputs in the examples folder so that you don't have to run anything to give feedback.

### Little CLI

[](#little-cli)

`dynamic.php` is a little cli for dynamically fetching the dom of some url. You can optionally pass a root selector as second argument.

This script was mainly built for testing in the early stages, and we have no intention to develop it further for now.

```
$ php examples/dynamic.php https://blog.algolia.com/inside-the-algolia-engine-part-2-the-indexing-challenge-of-instant-search/ article.post

```

Dev
---

[](#dev)

Test the code.

```
vendor/bin/phpunit

```

Contributing
------------

[](#contributing)

Please do contribute:

- if you have an idea, a question or just want to say hi: create an issue
- if you have a bug fix: create a PR

Please ensure the tests passes and also please run [php-cs-fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer) to ensure the code styles remain consistent.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community21

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 89.5% 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 ~279 days

Recently: every ~583 days

Total

10

Last Release

1131d ago

PHP version history (2 changes)0.0.1PHP &gt;=5.3

0.7.0PHP &gt;=5.6

### Community

Maintainers

![](https://www.gravatar.com/avatar/41b2c9ca6c01f18e470d2b1978227f8538e7af7031b8b05235aed5f6e186c2f1?d=identicon)[RayRutjes](/maintainers/RayRutjes)

---

Top Contributors

[![rayrutjes](https://avatars.githubusercontent.com/u/5570853?v=4)](https://github.com/rayrutjes "rayrutjes (34 commits)")[![nedmas](https://avatars.githubusercontent.com/u/842280?v=4)](https://github.com/nedmas "nedmas (2 commits)")[![DevinCodes](https://avatars.githubusercontent.com/u/46448173?v=4)](https://github.com/DevinCodes "DevinCodes (1 commits)")[![julienbourdeau](https://avatars.githubusercontent.com/u/1525636?v=4)](https://github.com/julienbourdeau "julienbourdeau (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/algolia-php-dom-parser/health.svg)

```
[![Health](https://phpackages.com/badges/algolia-php-dom-parser/health.svg)](https://phpackages.com/packages/algolia-php-dom-parser)
```

###  Alternatives

[ruflin/elastica

Elasticsearch Client

2.3k50.4M203](/packages/ruflin-elastica)[opensearch-project/opensearch-php

PHP Client for OpenSearch

15224.3M65](/packages/opensearch-project-opensearch-php)[mailerlite/laravel-elasticsearch

An easy way to use the official PHP ElasticSearch client in your Laravel applications.

934529.3k2](/packages/mailerlite-laravel-elasticsearch)[massive/search-bundle

Massive Search Bundle

721.4M13](/packages/massive-search-bundle)[shyim/opensearch-php-dsl

OpenSearch/Elasticsearch DSL library

175.9M9](/packages/shyim-opensearch-php-dsl)[outl1ne/nova-multiselect-filter

Multiselect filter for Laravel Nova.

45802.7k3](/packages/outl1ne-nova-multiselect-filter)

PHPackages © 2026

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