PHP Classes
elePHPant
Icontem

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

Recommend this page to a friend!
  Info   View files View files (19)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2013-09-25 (3 years ago) RSS 2.0 feedNot yet rated by the usersTotal: 281 All time: 7,147 This week: 900Up
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  
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

  Files folder image Files  /  classes  
File Role Description
Files folder imagecss-parser (5 files, 1 directory)
Files folder imageparser (2 files, 1 directory)

  Files folder image Files  /  classes  /  css-parser  
File Role Description
Files folder imagefilters (7 files)
  Accessible without login Plain text file css-element.php Class CSSElement class
  Accessible without login Plain text file css-factor.php Class CSSFactor class
  Accessible without login Plain text file css-helper.php Class Class source
  Accessible without login Plain text file css-parser.php Class CSSParser class
  Accessible without login Plain text file css-term.php Class CSSTerm class

  Files folder image Files  /  classes  /  css-parser  /  filters  
File Role Description
  Accessible without login Plain text file css-attr-filter.php Class CSSAttrFilter class
  Accessible without login Plain text file css-class-filter.php Class CSSClassFilter class
  Accessible without login Plain text file css-filter.php Class CSSFilter class
  Accessible without login Plain text file css-id-filter.php Class CSSIdFilter class
  Accessible without login Plain text file css-pseudo-filter.php Class CSSPseudoFilter class
  Accessible without login Plain text file css-pseudo-first-child-filter.php Class CSSPseudoFirstChild class
  Accessible without login Plain text file css-pseudo-nth-child-filter.php Class CSSPseudoNthChildFilter class

  Files folder image Files  /  classes  /  parser  
File Role Description
Files folder imageexceptions (1 file)
  Accessible without login Plain text file parser.php Class Parser class
  Accessible without login Plain text file tokenizer.php Class Tokenizer class

  Files folder image Files  /  classes  /  parser  /  exceptions  
File Role Description
  Accessible without login Plain text file parser-exception.php Class ParserException class

 Version Control Unique User Downloads Download Rankings  
 100%
Total:281
This week:0
All time:7,147
This week:900Up