PHPackages                             hugsbrugs/php-xpath - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. hugsbrugs/php-xpath

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

hugsbrugs/php-xpath
===================

PHP XPath Utilities

v1.2(5y ago)14831HTML

Since Apr 19Pushed 2y ago1 watchersCompare

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

READMEChangelog (2)Dependencies (1)Versions (4)Used By (1)

php-xpath
=========

[](#php-xpath)

This librairy provides utilities function to ease xpath manipulation

[![Build Status](https://camo.githubusercontent.com/4b2b60ab20af4e93daaf78fce322affb3caa978989afe85642fe10e350490cae/68747470733a2f2f7472617669732d63692e6f72672f6875677362727567732f7068702d78706174682e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/hugsbrugs/php-xpath)[![Coverage Status](https://camo.githubusercontent.com/1b72db4e64f202d1d8b2e2b4b696854157bc7e6578a1ce6453c9e4833f658ace/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6875677362727567732f7068702d78706174682f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/hugsbrugs/php-xpath?branch=master)

Install
-------

[](#install)

Install package with composer

```
composer require hugsbrugs/php-xpath

```

In your PHP code, load librairy

```
require_once __DIR__ . '/../vendor/autoload.php';
use Hug\Xpath\Xpath as Xpath;
```

Usage
-----

[](#usage)

Extracts all elements matching query

```
Xpath::extract_all($html, $query = '//a');
```

Extracts first element matching query

```
Xpath::extract_first($html, $query = '//body//h3');
```

Extracts body of HTML document

```
Xpath::get_body($html);
```

Replaces body of HTML document

```
Xpath::replace_body($html, $new_body = 'Hello World !');
```

XPath fails at extracting html tags style attributes content so this function makes it !

```
Xpath::extract_style($html, $query = '//body//div[@class="inscriptionadsl"]', $style_property = 'height');
```

Extract first iframe from a webpage matching a given domain name

```
Xpath::extract_iframe($html, $domain = 'hugo.maugey.fr');
```

Unit Tests
----------

[](#unit-tests)

```
phpunit --bootstrap vendor/autoload.php tests

```

Author
------

[](#author)

Hugo Maugey [visit my website ;)](https://hugo.maugey.fr)

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity61

Established project with proven stability

 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 ~291 days

Total

3

Last Release

2000d ago

### Community

Maintainers

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

---

Top Contributors

[![hugsbrugs](https://avatars.githubusercontent.com/u/4385090?v=4)](https://github.com/hugsbrugs "hugsbrugs (6 commits)")

### Embed Badge

![Health badge](/badges/hugsbrugs-php-xpath/health.svg)

```
[![Health](https://phpackages.com/badges/hugsbrugs-php-xpath/health.svg)](https://phpackages.com/packages/hugsbrugs-php-xpath)
```

###  Alternatives

[recolize/module-recommendation-engine-magento2

The Recolize Recommendation Engine Extension for Magento 2

115.0k](/packages/recolize-module-recommendation-engine-magento2)

PHPackages © 2026

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