An open API service indexing awesome lists of open source software.

https://github.com/tj/php-selector

PHP DOM parser / queries with CSS selectors
https://github.com/tj/php-selector

Last synced: 9 months ago
JSON representation

PHP DOM parser / queries with CSS selectors

Awesome Lists containing this project

README

          

= PHP Selector

Quick DOM query library I whipped up for an old
PHP data miner I had which needed more flexibility.

Current supports most CSS3 selectors.

Tested with php 5.2.8

== Examples

Given the sample html:

$html = <<

Article Name


Contents of article



  • One

  • Two

  • Three

  • Four

  • Five



HTML;

The following will return an array of elements:

select_elements('div#article.large', $html);
select_elements('div > h2:contains(Article)', $html);
select_elements('div p + ul', $html);
select_elements('ul > li:first-child', $html);
select_elements('ul > li ~ li', $html);
select_elements('ul > li:last-child', $html);
select_elements('li a[href=#]', $html);

== SelectorDOM

Persistant object for element selection.

$dom = new SelectorDOM($html);
$links = $dom->select('a');
$list_links = $dom->select('ul li a');

== Contribution

* Like it? use it? feel free to extend and add more CSS3 support, and
run test.selector.php

== More Information

* View the source :P

== License

(The MIT License)

Copyright (c) 2008 - 2009 TJ Holowaychuk

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.