2017 © Pedro Pelรกez
 

library phpcss

An css selector parser and converter

image

carica/phpcss

An css selector parser and converter

  • Wednesday, June 27, 2018
  • by ThomasWeinert
  • Repository
  • 8 Watchers
  • 65 Stars
  • 3,508 Installations
  • PHP
  • 2 Dependents
  • 1 Suggesters
  • 11 Forks
  • 1 Open issues
  • 12 Versions
  • 8 % Grown

The README.md

PhpCss - PHP CSS Parser Library

Build Status License Total Downloads Latest Stable Version Latest Unstable Version, (*1)

Thanks to Benjamin Eberlei, Bastian Feder and Jakob Westhoff for ideas and concepts., (*2)

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., (*3)

The main target of this project is the possibilty to convert CSS selectors into Xpath expressions., (*4)

Demo

A small demo application can be found at: http://xpath.thomas.weinert.info/, (*5)

Installation

PhpCss is available on Packagist: Carica/PhpCss. Add it to you composer.json and update., (*6)

Basic Usage

Get CSS selector as Xpath expression, (*7)

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

Reformat/Validate CSS Selector, (*8)

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

Get the AST, (*9)

$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:, (*10)

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

Supported

Selector to CSS to 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 โœ“ โœ“

The Versions

27/06 2018

dev-master

9999999-dev

An css selector parser and converter

  Sources   Download

MIT MIT License

The Requires

  • php >=7.0

 

by Thomas Weinert

27/06 2018

1.0.2

1.0.2.0

An css selector parser and converter

  Sources   Download

MIT

The Requires

  • php >=7.0

 

by Thomas Weinert

20/06 2018

1.0.1

1.0.1.0

An css selector parser and converter

  Sources   Download

MIT

The Requires

  • php >=7.0

 

by Thomas Weinert

12/04 2018

1.0.0

1.0.0.0

An css selector parser and converter

  Sources   Download

MIT

The Requires

  • php >=7.0

 

by Thomas Weinert

12/04 2018

dev-PhpCss-11

dev-PhpCss-11

An css selector parser and converter

  Sources   Download

MIT

The Requires

  • php >=7.0

 

by Thomas Weinert

02/04 2018

0.5.0

0.5.0.0

An css selector parser and converter

  Sources   Download

MIT

The Requires

  • php >=7.0

 

by Thomas Weinert

09/08 2016

0.4.0

0.4.0.0

An css selector parser and converter

  Sources   Download

MIT License

The Requires

  • php >=5.5

 

by Thomas Weinert

23/06 2014

0.3.x-dev

0.3.9999999.9999999-dev

An css selector parser and converter

  Sources   Download

MIT License

The Requires

  • php >=5.5

 

by Thomas Weinert

23/06 2014

0.3.0

0.3.0.0

An css selector parser and converter

  Sources   Download

MIT License

The Requires

  • php >=5.5

 

by Thomas Weinert

13/06 2014

0.2.x-dev

0.2.9999999.9999999-dev

An css selector parser and converter

  Sources   Download

MIT License

The Requires

  • php >=5.5

 

by Thomas Weinert

13/06 2014

0.2.0

0.2.0.0

An css selector parser and converter

  Sources   Download

MIT License

The Requires

  • php >=5.5

 

by Thomas Weinert

30/05 2014

0.1.0

0.1.0.0

An css selector parser and converter

  Sources   Download

MIT License

The Requires

  • php >=5.5

 

by Thomas Weinert