PHPackages                             carica/phpcss - 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. carica/phpcss

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

carica/phpcss
=============

An css selector parser and converter

2.0.0(5y ago)7270.2k↓34.7%10[3 issues](https://github.com/ThomasWeinert/PhpCss/issues)3MITPHPPHP &gt;=7.2

Since May 30Pushed 5y ago8 watchersCompare

[ Source](https://github.com/ThomasWeinert/PhpCss)[ Packagist](https://packagist.org/packages/carica/phpcss)[ RSS](/packages/carica-phpcss/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (9)DependenciesVersions (12)Used By (3)

PhpCss - PHP CSS Parser Library
===============================

[](#phpcss---php-css-parser-library)

[![Build Status](https://camo.githubusercontent.com/dada7bc165182931a931f64d75ae858cf479b0a3bbd8705592f94ed94b51236e/68747470733a2f2f7472617669732d63692e6f72672f54686f6d61735765696e6572742f5068704373732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/ThomasWeinert/PhpCss)[![License](https://camo.githubusercontent.com/e79f327efa7c1ec8c4ae862ce7a99447805eb442572b0a34e58cbe5c4fc9e929/68747470733a2f2f706f7365722e707567782e6f72672f6361726963612f7068706373732f6c6963656e73652e737667)](https://packagist.org/packages/carica/phpcss)[![Total Downloads](https://camo.githubusercontent.com/8d2af27f0d07ec32010b9ed679ae0c3281c56c987a6ad2dc3adaeb002b3bb343/68747470733a2f2f706f7365722e707567782e6f72672f6361726963612f7068706373732f646f776e6c6f6164732e737667)](https://packagist.org/packages/carica/phpcss)[![Latest Stable Version](https://camo.githubusercontent.com/2d1ca0fafb2d3aafe9f2cbfb5dae34777a5a050fa46b33e5ca934ffa5ae51a21/68747470733a2f2f706f7365722e707567782e6f72672f6361726963612f7068706373732f762f737461626c652e737667)](https://packagist.org/packages/carica/phpcss)[![Latest Unstable Version](https://camo.githubusercontent.com/76f3fa973778ce1dc00e638dc8af293b43cfa939f860359c29eaa7471ae8139c/68747470733a2f2f706f7365722e707567782e6f72672f6361726963612f7068706373732f762f756e737461626c652e737667)](https://packagist.org/packages/carica/phpcss)

- License: The MIT License
- Copyright: 2010-2018 PhpCss Team
- Author: [Thomas Weinert](http://thomas.weinert.info)

Thanks to Benjamin Eberlei, Bastian Feder and Jakob Westhoff for ideas and concepts.

PhpCSS is a parser for CSS 3 selectors. It parses them into an AST and allows them to compile the AST to CSS selectors or Xpath expressions.

The main target of this project is the possibilty to convert CSS selectors into Xpath expressions.

Demo
----

[](#demo)

A small demo application can be found at:

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

[](#installation)

PhpCss is available on Packagist: [Carica/PhpCss](https://packagist.org/packages/carica/phpcss). Add it to you composer.json and update.

Basic Usage
-----------

[](#basic-usage)

Get CSS selector as Xpath expression

```
$expression = PhpCss::toXpath($selector);

```

Reformat/Validate CSS Selector

```
$selector = PhpCss::reformat($selector);

```

Get the AST

```
$ast = PhpCss::getAst($selector);

```

FluentDOM
---------

[](#fluentdom)

[FluentDOM 5](https://github.com/FluentDOM/FluentDOM) allows to inject a callback to convert selectors. If you have FluentDOM and PhpCss installed in your project, you can use CSS selectors in FluentDOM:

```
$fd = FluentDOM::QueryCss($xml);
$fd
  ->find('td:nth-of-type(even)')
  ->addClass('even');

```

Supported
---------

[](#supported)

   Selectorto CSSto Xpath     \*✓✓   E✓✓   ns|\*✓✓   ns|E✓✓   Attributes   E\[foo\]✓✓   E\[foo="bar"\]✓✓   E\[foo~="bar"\]✓✓   E\[foo^="bar"\]✓✓   E\[foo$="bar"\]✓✓   E\[foo\*="bar"\]✓✓   E\[foo|="bar"\]✓✓   Structural Pseudo Classes   E:root✓✓   E:nth-child(42)✓✓   E:nth-last-child(42)✓✓   E:nth-of-type(42)✓✓   E:nth-last-of-type(42)✓✓   E:first-child✓✓   E:last-child✓✓   E:first-of-type✓✓   E:last-of-type✓✓   E:only-child✓✓   E:only-of-type✓✓   E:empty✓✓   Link Pseudo Classes   E:link✓✗   E:visited✓✗   User Action Pseudo Classes   E:active✓✗   E:hover✓✗   E:focus✓✗   Target Pseudo Class   E:target✓✗   Language Pseudo Class   E:lang(fr)✓✓   UI Element states Pseudo Class   E:enabled✓✓ (not disabled)   E:disabled✓✓ (attribute)   E:checked✓✓ (attribute)   Pseudo Elements   E:first-line✓✗   E:first-letter✓✗   E:before✓✗   E:after✓✗   Class Selector   E.warning✓✓   Id Selector   E#myid✓✓   Negation Pseudo Class   E:not(s)✓✓   Combinators   E F✓✓   E &gt; F✓✓   E + F✓✓   E ~ F✓✓   jQuery   :contains("text")✓✓   :has(s)✓✓   :gt(42)✓✓   :lt(42)✓✓   :odd✓✓   :even✓✓

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity44

Moderate usage in the ecosystem

Community21

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 99.1% 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 ~252 days

Recently: every ~279 days

Total

11

Last Release

1849d ago

Major Versions

0.5.0 → 1.0.02018-04-12

1.0.2 → 2.0.02021-04-25

PHP version history (3 changes)0.1.0PHP &gt;=5.5

0.5.0PHP &gt;=7.0

2.0.0PHP &gt;=7.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/236825?v=4)[Thomas Weinert](/maintainers/ThomasWeinert)[@ThomasWeinert](https://github.com/ThomasWeinert)

---

Top Contributors

[![ThomasWeinert](https://avatars.githubusercontent.com/u/236825?v=4)](https://github.com/ThomasWeinert "ThomasWeinert (211 commits)")[![hakre](https://avatars.githubusercontent.com/u/378849?v=4)](https://github.com/hakre "hakre (2 commits)")

### Embed Badge

![Health badge](/badges/carica-phpcss/health.svg)

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

###  Alternatives

[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

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

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)[jms/serializer-bundle

Allows you to easily serialize, and deserialize data of any complexity

1.8k89.3M627](/packages/jms-serializer-bundle)[hassankhan/config

Lightweight configuration file loader that supports PHP, INI, XML, JSON, and YAML files

97513.5M170](/packages/hassankhan-config)[meyfa/php-svg

Read, edit, write, and render SVG files with PHP

54613.9M42](/packages/meyfa-php-svg)

PHPackages © 2026

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