PHP Classes

PHP CSS Parser: Get HTML document nodes matching a CSS selector

Recommend this page to a friend!
     
  Info   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 305 All time: 7,379 This week: 140Up
Version License PHP version Categories
css-parser 1.0.0BSD License5.3HTML, XML, PHP 5, Parsers
Description 

Author

This package can get HTML or XML document nodes matching a CSS selector.

It can parse a CSS query selector expression and find DOM document nodes that match the criteria defined by that expression.

The helper class can also return the HTML or XML string that represent a matching node.

Picture of Gonzalo Chumillas
Name: Gonzalo Chumillas <contact>
Classes: 8 packages by
Country: Spain Spain
Innovation award
Innovation award
Nominee: 2x

 

Details

# cssparser Evaluates a CSS selector expression and filters nodes from a given DOMNode object. For example: ```php // loads an xml document $doc = new DOMDocument("1.0", "UTF-8"); $doc->load('test.xml'); // filters nodes $p = new CSSParser($doc, 'books item.sci-fi.horror[author_id ^= theodore][author_id $= sturgeon]'); $nodes = $p->parse(); // prints nodes foreach ($nodes as $node) { echo CSSHelper::dom2str($node) . "\n~~~\n"; } ``` ### Supported features #### Basic selectors: 1. [All Selector (“*”)](http://api.jquery.com/all-selector/) 2. [Class Selector (“.class”)](http://api.jquery.com/class-selector/) 3. [Element Selector (“element”)](http://api.jquery.com/element-selector/) 4. [ID Selector (“#id”)](http://api.jquery.com/id-selector/) 5. [Multiple Selector (“selector1, selector2, selectorN”)](http://api.jquery.com/multiple-selector/) #### Child filters: 1. [:first-child Selector](http://api.jquery.com/first-child-selector/) 2. [:nth-child() Selector](http://api.jquery.com/nth-child-selector/) #### Attribute filters: 1. [Attribute Contains Prefix Selector \[name|="value"\]](http://api.jquery.com/attribute-contains-prefix-selector/) 2. [Attribute Contains Selector \[name*="value"\]](http://api.jquery.com/attribute-contains-selector/) 3. [Attribute Contains Word Selector \[name~="value"\]](http://api.jquery.com/attribute-contains-word-selector/) 4. [Attribute Ends With Selector \[name$="value"\]](http://api.jquery.com/attribute-ends-with-selector/) 5. [Attribute Equals Selector \[name="value"\]](http://api.jquery.com/attribute-equals-selector/) 6. [Attribute Not Equal Selector \[name!="value"\]](http://api.jquery.com/attribute-not-equal-selector/) 7. [Attribute Starts With Selector \[name^="value"\]](http://api.jquery.com/attribute-starts-with-selector/) 8. [Has Attribute Selector \[name\]](http://api.jquery.com/has-attribute-selector/) 9. [Multiple Attribute Selector \[name="value"\]\[name2="value2"\]](http://api.jquery.com/multiple-attribute-selector/)

  Files folder image Files (19)  
File Role Description
Files folder imageclasses (2 directories)
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file test.php Example Examples
Accessible without login Plain text file test.xml Data xml example

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:305
This week:0
All time:7,379
This week:140Up