# PhpCss - PHP CSS Parser Library [![Build Status](https://travis-ci.org/ThomasWeinert/PhpCss.svg?branch=master)](https://travis-ci.org/ThomasWeinert/PhpCss) [![License](https://poser.pugx.org/carica/phpcss/license.svg)](https://packagist.org/packages/carica/phpcss) [![Total Downloads](https://poser.pugx.org/carica/phpcss/downloads.svg)](https://packagist.org/packages/carica/phpcss) [![Latest Stable Version](https://poser.pugx.org/carica/phpcss/v/stable.svg)](https://packagist.org/packages/carica/phpcss) [![Latest Unstable Version](https://poser.pugx.org/carica/phpcss/v/unstable.svg)](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 A small demo application can be found at: http://xpath.thomas.weinert.info/ ## Installation PhpCss is available on Packagist: [Carica/PhpCss](https://packagist.org/packages/carica/phpcss). Add it to you composer.json and update. ## 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 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
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 > F
E + F
E ~ F
jQuery
:contains("text")
:has(s)
:gt(42)
:lt(42)
:odd
:even