deimos/qparser

This package is abandoned and no longer maintained. No replacement package was suggested.
There is no license information available for the latest version (1.1.10) of this package.

1.1.10 2016-03-25 22:55 UTC

This package is not auto-updated.

Last update: 2023-08-19 12:29:50 UTC


README

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.4

Example

Given the sample html:

$html = <<<HTML
<div id="article" class="block large">
  <h2>Article Name</h2>
  <p>Contents of article</p>
  <ul>
    <li>One</li>
    <li>Two</li>
    <li>Three</li>
    <li>Four</li>
    <li><a href="#">Five</a></li>
  </ul>
</div>
HTML;

The following will return an array of elements:

$qParser = new \Deimos\QParser($html);

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