carica / phpcss
An css selector parser and converter
Installs: 58 462
Dependents: 3
Suggesters: 0
Security: 0
Stars: 71
Watchers: 11
Forks: 10
Open Issues: 3
Requires
- php: >=7.2
README
- License: The MIT License
- Copyright: 2010-2018 PhpCss Team
- Author: Thomas Weinert 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. 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 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');