iamcal/pquery

A jQuery-style DOM traversal tool, for PHP

v1.0.0 2021-01-23 01:55 UTC

This package is auto-updated.

Last update: 2024-12-06 00:24:33 UTC


README

Build Status Coverage Status Latest Stable Version

Beware! There are several projects with the name pQuery. You might be looking for a different one.

This PHP library allows you to use jQuery-style selectors to find DOM nodes in HTML documents. It uses the PHP DOM classes under the covers, which ultimately use libxml for document parsing.

Installation

You can install using composer:

composer require iamcal/pquery

This will put the pQuery class into the autoloader in vendor/autoload.php.

Alertnatively you can clone this repo and include src/pQuery.php directly.

Basic Usage

$html = '<p>Hello <b>World</b></p>';

$pq = pQuery::fromHTML($html);

$nodes = $pq->find('b');
// $nodes is an array of DOMNode objects

Supported selectors:

tag
tag.class
tag#id
.class
#id

Selectors can be chained together, e.g. table#my-table th a.info