PHPackages                             zxqfox/css-selector-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. zxqfox/css-selector-parser

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

zxqfox/css-selector-parser
==========================

Simple CSS selector parser. PHP port of https://github.com/mdevils/node-css-selector-parser

0.0.5(11y ago)311.0kMITPHPPHP &gt;=5.4.0

Since Oct 27Pushed 11y agoCompare

[ Source](https://github.com/zxqfox/php-css-selector-parser)[ Packagist](https://packagist.org/packages/zxqfox/css-selector-parser)[ RSS](/packages/zxqfox-css-selector-parser/feed)WikiDiscussions master Synced 1mo ago

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

php-css-selector-parser
=======================

[](#php-css-selector-parser)

Fast and low memory CSS selector parser.

Parses CSS selector into object-model.

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

[](#installation)

```
composer require zxqfox/css-selector-parser

```

Usage
-----

[](#usage)

```
use CSSSelectorParser\Parser;

$parser = new Parser();

$parser->registerSelectorPseudos('has');
$parser->registerNestingOperators('>', '+', '~');
$parser->registerAttrEqualityMods('^', '$', '*', '~');
$parser->enableSubstitutes();

$css = 'a[href^=/], .container:has(nav) > a[href]:lt($var)';
echo json_encode($parser->parse($css), JSON_PRETTY_PRINT);
```

Produces:

```
{ type: 'selectors',
  selectors:
   [ { type: 'ruleSet',
       rule:
        { tagName: 'a',
          attrs: [ { name: 'href', operator: '^=', valueType: 'string', value: '/' } ],
          type: 'rule' } },
     { type: 'ruleSet',
       rule:
        { classNames: [ 'container' ],
          pseudos:
           [ { name: 'has',
               valueType: 'selector',
               value: { type: 'ruleSet', rule: { tagName: 'nav', type: 'rule' } } } ],
          type: 'rule',
          rule:
           { tagName: 'a',
             attrs: [ { name: 'href' } ],
             pseudos: [ { name: 'lt', valueType: 'substitute', value: 'var' } ],
             nestingOperator: '>',
             type: 'rule' } } } ] }

```

Token description
-----------------

[](#token-description)

*type* may be one of:

- *selectors* — list of selectors, token contains *selectors* array of *ruleSet* tokens (based on "," operator).
- *ruleSet* — selector, token contains *rule* field with *rule*-type object.
- *rule* — single rule.

Fields for *rule* type.

- *tagName* — tag name for the rule (e.g. "div"), may be '\*'.
- *classNames* — list of CSS class names for the rule.
- *attrs* — list of attribute rules; rule may contain fields:
    - *name* — attribute name, required field.
    - *valueType* — type of comparison value ("string" or "substitute").
    - *operator* — attribute value comparison operator.
    - *value* — comparison attribute value.
- *pseudos* — list of pseudo class rules; rule may contain fields:
    - *name* — pseudo name, required field.
    - *valueType* — argument type ("string", "selector" or "substitute").
    - *value* — pseudo argument.
- *nestingOperator* — the operator used to nest this rule (e.g. in selector "tag1 &gt; tag2", tag2 will have nestingOperator="&gt;")
- *rule* — nested rule.

License
-------

[](#license)

MIT

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

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

4

Last Release

4221d ago

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

0.0.4PHP &gt;=5.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/273c3a9702495ba0ebc3e3ec1a3008e9414c256a96e452c37e605c235fb55363?d=identicon)[zxqfox](/maintainers/zxqfox)

---

Tags

csscss-selectorcss selector parser

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/zxqfox-css-selector-parser/health.svg)

```
[![Health](https://phpackages.com/badges/zxqfox-css-selector-parser/health.svg)](https://phpackages.com/packages/zxqfox-css-selector-parser)
```

###  Alternatives

[components/flag-icon-css

A curated collection of all country flags in SVG — plus the CSS for easier integration.

12.0k1.6M23](/packages/components-flag-icon-css)[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)[scssphp/scssphp

scssphp is a compiler for SCSS written in PHP.

62827.7M220](/packages/scssphp-scssphp)[mexitek/phpcolors

A series of methods that let you manipulate colors. Just incase you ever need different shades of one color on the fly.

5003.6M18](/packages/mexitek-phpcolors)[wikimedia/less.php

PHP port of the LESS processor

12327.4M77](/packages/wikimedia-lessphp)[cerdic/css-tidy

CSSTidy is a CSS minifier

2092.0M6](/packages/cerdic-css-tidy)

PHPackages © 2026

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