bkuhl/php-selector

v1.0 2017-10-13 14:53 UTC

This package is auto-updated.

Last update: 2022-06-09 23:50:45 UTC


README

Latest Stable Version Total Downloads Build Status

A simple DOM query library originally written by tj.

Installation

composer require bkuhl/php-selector:~1.0

Usage

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:

$dom = new \PHPSelector\Dom($html);

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