bkuhl/php-selector

Installs: 10 947

Dependents: 0

Suggesters: 0

Security: 0

Stars: 14

Watchers: 1

Forks: 117

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

This package is auto-updated.

Last update: 2024-10-10 04:46:26 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=#]'));