PHPackages                             bdk/css-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. bdk/css-xpath

ActiveLibrary

bdk/css-xpath
=============

Search html via CSS selector or convert css selector to xpath

v1.0.2(6mo ago)931.2k↓42.3%12MITPHPPHP &gt;=5.3.0CI passing

Since Feb 1Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/bkdotcom/CssXpath)[ Packagist](https://packagist.org/packages/bdk/css-xpath)[ Docs](http://github.com/bkdotcom/CssXpath)[ RSS](/packages/bdk-css-xpath/feed)WikiDiscussions master Synced 1mo ago

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

CssXpath
========

[](#cssxpath)

- Convert CSS selector to XPath
- Query HTML string (or \\DOMDocument) by CSS selector
- Provide PHPUnit Assertions (once provided by PHPUnit)

[![No Dependencies](https://camo.githubusercontent.com/d27fafbf57b29a6865661e1e03080c79445278b95165e3152cd83352873a63fc/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646570656e64656e636965732d6e6f6e652d3333333333332e737667)](https://camo.githubusercontent.com/d27fafbf57b29a6865661e1e03080c79445278b95165e3152cd83352873a63fc/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646570656e64656e636965732d6e6f6e652d3333333333332e737667)[![Supported PHP versions](https://camo.githubusercontent.com/37140af4bc1c3c23bb29b3e054a22fffeccbb8a685c47d28672a70d1b957c908/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d504850266d6573736167653d352e342532302d253230382e3526636f6c6f723d626c7565)](https://camo.githubusercontent.com/37140af4bc1c3c23bb29b3e054a22fffeccbb8a685c47d28672a70d1b957c908/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d504850266d6573736167653d352e342532302d253230382e3526636f6c6f723d626c7565)[![Build Status](https://camo.githubusercontent.com/bdd56da4e58945af0a03288044a270ec3a0e3eb58034c19ceb08ba45bedbf7bd/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f626b646f74636f6d2f43737358706174682f706870756e69742e796d6c2e7376673f6c6f676f3d676974687562)](https://camo.githubusercontent.com/bdd56da4e58945af0a03288044a270ec3a0e3eb58034c19ceb08ba45bedbf7bd/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f626b646f74636f6d2f43737358706174682f706870756e69742e796d6c2e7376673f6c6f676f3d676974687562)

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

[](#installation)

```
composer require bdk/css-xpath

```

Usage
-----

[](#usage)

### CSS to XPath

[](#css-to-xpath)

```
\bdk\CssXpath\CssXpath::cssToXpath('ul > li:first-child');	// returns '//ul/li[1]'
```

### Query DOM/HTML

[](#query-domhtml)

Example:

```
$html = select('ul > li:last-child [href]');
```

Output:

```
array (size=1)
  0 =>
    array (size=3)
      'name' => string 'a' (length=1)
      'attributes' =>
        array (size=1)
          'href' => string '#' (length=1)
      'innerHTML' => string 'Five' (length=4)

```

Pass a last argument of `true`, to return a `\DOMNodeList` object instead of an array

### PHPUnit

[](#phpunit)

`bdk\CssXpath\DOMTestCase` extends `\PHPUnit\Framework\TestCase` and provides 3 assertions:

- `assertSelectCount($selector, $count, $actual, $message = '')`
- `assertSelectRegExp($selector, $pattern, $count, $actual, $message = '')`
- `assertSelectEquals($selector, $content, $count, $actual, $message = '')`

[These assertions](https://phpunit.de/manual/3.7/en/writing-tests-for-phpunit.html#writing-tests-for-phpunit.assertions.assertSelectCount) were originally provided with PHPUnit 3.3, but removed with PHPUnit 5.0

###  Health Score

48

—

FairBetter than 95% of packages

Maintenance69

Regular maintenance activity

Popularity34

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 95.8% 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 ~1423 days

Total

3

Last Release

182d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/573f67023e7d41ccd0618b6732cc908e1a30f5d0df514b792b0ebc5379f9d659?d=identicon)[brad.kent](/maintainers/brad.kent)

---

Top Contributors

[![bkdotcom](https://avatars.githubusercontent.com/u/2137404?v=4)](https://github.com/bkdotcom "bkdotcom (23 commits)")[![muxator](https://avatars.githubusercontent.com/u/4067621?v=4)](https://github.com/muxator "muxator (1 commits)")

---

Tags

cssXpath

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/bdk-css-xpath/health.svg)

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

###  Alternatives

[nunomaduro/termwind

It's like Tailwind CSS, but for the console.

2.5k239.8M286](/packages/nunomaduro-termwind)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M65](/packages/sabberworm-php-css-parser)[matthiasmullie/minify

CSS &amp; JavaScript minifier, in PHP. Removes whitespace, strips comments, combines files (incl. @import statements and small assets in CSS files), and optimizes/shortens a few common programming patterns.

2.0k30.5M336](/packages/matthiasmullie-minify)[pelago/emogrifier

Converts CSS styles into inline style attributes in your HTML code

94944.1M110](/packages/pelago-emogrifier)[scssphp/scssphp

scssphp is a compiler for SCSS written in PHP.

62827.7M220](/packages/scssphp-scssphp)[tubalmartin/cssmin

A PHP port of the YUI CSS compressor

23141.0M53](/packages/tubalmartin-cssmin)

PHPackages © 2026

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