Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

143 lines (106 sloc) 3.622 kB

QueryPath: Find your way.

New development is happening on the 3.x branch.

Authors: Matt Butcher (lead), Emily Brand, and many others

Website | API Docs | VCS and Issue Tracking | Support List | Developer List | Pear channel |

This package is licensed under an MIT license (COPYING-MIT.txt) or, at your option, the LGPL version 2.1 or later. The licenses should have been distributed with this library.

At A Glance

QueryPath is a jQuery-like library for working with XML and HTML documents in PHP.

Say we have a document like this:

<?xml version="1.0"?>
  <tr id="row1">
  <tr id="row2">

And say that the above is stored in the variable $xml. Now we can use QueryPath like this:

// Get all of the <td> elements in the document and add the
// attribute `foo='bar'`:
qp($xml, 'td')->attr('foo', 'bar');

// Or print the contents of the third TD in the second row:
print qp($xml, '#row2>td:nth(3)')->text();

// Or append another row to the XML and then write the 
// result to standard output:
qp($xml, 'tr:last')->after('<tr><td/><td/><td/></tr>')->writeXML();


(This example is in examples/at-a-glance.php.)

With over 60 functions and robust support for chaining, you can accomplish sophisticated XML and HTML processing using QueryPath.

QueryPath Installers

The following packages of QueryPath are available:

  • A PEAR package (pear install querypath/QueryPath): Installs the library and documentation.
  • A download from the GitHub Tags page.
  • Via Composer


To add QueryPath as a library in your project, add this to the 'require' section of your composer.json:

  "require": {
    "querypath/QueryPath": ">=2.0.0"

The run php composer.phar install in that directory.


To install QueryPath as a server-wide library, you may wish to use PEAR or Pyrus. See for more information, or simply run these commands:

$ pear channel-discover
$ pear install querypath/QueryPath


You can either download a stable release from the GitHub Tags page or you can use git to clone this repository and work from the code. master typically has the latest stable, while 3.x is where active development is happening.

Including QueryPath

As of QueryPath 3.x, QueryPath uses the Composer autoloader if you installed with composer:

require 'vendor/autoload.php';

// Optional: Use this to load `qp()` and `htmlqp()`
require 'vendor/querypath/QueryPath/src/qp.php';

If you installed QueryPath as a PEAR package, use it like this:

require 'QueryPath/qp.php';

From the download or git clone:

require 'QueryPath/src/QueryPath/qp.php';

With the Phar archive, you can include QueryPath like this:

require 'QueryPath.phar';

From there, the main functions you will want to use are qp() (alias of QueryPath::with()) and htmlqp() (alias of QueryPath::withHTML()). Start with the API docs.

Jump to Line
Something went wrong with that request. Please try again.