| 1 |
# pQuery |
| 2 |
|
| 3 |
[](https://travis-ci.org/tburry/pquery](https://travis-ci.org/tburry/pquery](https://travis-ci.org/tburry/pquery) |
| 4 |
[](https://scrutinizer-ci.com/g/tburry/pquery/](https://scrutinizer-ci.com/g/tburry/pquery/](https://scrutinizer-ci.com/g/tburry/pquery/) |
| 5 |
[](https://packagist.org/packages/tburry/pquery](https://packagist.org/packages/tburry/pquery](https://packagist.org/packages/tburry/pquery) |
| 6 |
|
| 7 |
pQuery is a jQuery like html dom parser written in php. It is a fork of the [](https://code.google.com/p/ganon/ganon dom parser](https://code.google.com/p/ganon/](https://code.google.com/p/ganon/). |
| 8 |
|
| 9 |
## Basic usage |
| 10 |
|
| 11 |
To get started using pQuery do the following. |
| 12 |
|
| 13 |
1. Require the pQuery library into your project using [](http://getcomposer.org/doc/01-basic-usage.md#the-require-keycomposer](http://getcomposer.org/doc/01-basic-usage.md#the-require-key](http://getcomposer.org/doc/01-basic-usage.md#the-require-key). |
| 14 |
2. Parse a snippet of html using `pQuery::parseStr()` or `pQuery::parseFile()` to return a document object model (DOM). |
| 15 |
3. Run jQuery like functions on the DOM. |
| 16 |
|
| 17 |
## Example |
| 18 |
|
| 19 |
The following example parses an html string and does some manipulation on it. |
| 20 |
|
| 21 |
```php |
| 22 |
$html = '<div class="container"> |
| 23 |
<div class="inner verb">Hello</div> |
| 24 |
<div class="inner adj">Cruel</div> |
| 25 |
<div class="inner obj">World</div> |
| 26 |
</div>'; |
| 27 |
|
| 28 |
$dom = pQuery::parseStr($html); |
| 29 |
|
| 30 |
$dom->query('.inner') |
| 31 |
->tagName('span'); |
| 32 |
|
| 33 |
$dom->query('.adj') |
| 34 |
->html('Beautiful') |
| 35 |
->tagName('i'); |
| 36 |
|
| 37 |
echo $dom->html(); |
| 38 |
``` |
| 39 |
|
| 40 |
## Differences between pQuery and ganon |
| 41 |
|
| 42 |
pQuery is a fork of the [ganon php processor](https://code.google.com/p/ganon/). Most of the functionality is identical to ganon with the following exceptions. |
| 43 |
|
| 44 |
* pQuery is a composer package. |
| 45 |
* pQuery renames ganon's classes and puts them into a namespace. |
| 46 |
* pQuery is used only with objects rather than functions so that it can be autoloaded. |
| 47 |
* pQuery Adds the `IQuery` interface and the `pQuery` object that define the jQuery-like interface for querying the dom. |
| 48 |
* pQuery implements more of jQuery's methods. See the `IQuery` interface for a list of methods. |
| 49 |
* pQuery supports adding tags to the dom using the `<div class="something"></div>` notation rather than just `div`. |
| 50 |
|