PHPackages                             rudestan/domquery - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. rudestan/domquery

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

rudestan/domquery
=================

A simple and easy to use library for selecting DOM elements similar to jQuery's Sizzle.

06PHP

Since Mar 11Pushed 10y ago1 watchersCompare

[ Source](https://github.com/rudestan/domQuery)[ Packagist](https://packagist.org/packages/rudestan/domquery)[ RSS](/packages/rudestan-domquery/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

domQuery
========

[](#domquery)

domQuery is a simple small library for selecting DOM Elements in a jQuery's manner. It is not a full analogue of jQuery library, even not all selectors are yet implemented however it already allows you to use main selectors and attribute modifiers (such as name|=, name~= etc.).

It is easy and fast to write a web-site grabber using domQuery, because you do not have to use regular expressions - just use usual jQuery selectors with domQuery and write only couple of lines of code.

Overall domQuery actually converts jQuery's selectors into DOMXPath query and the executes it. Library will be updated with some new features, bug fixes etc.

There are some PHPUnit tests (in test dir) which uses html and selectors from jQuery's API documentation.

Usage
-----

[](#usage)

You could create a new instance of domQuery in a regular way and then execute a query:

```
 $dQ = new domQuery\Selector($doc);
 $dQ->q('.myClass');
```

Or just use static wrapper:

```
 $dQ = domQuery\Selector::i($document)->q('.myClass');
```

The results returned as an Array of objects (array of domQuery\\Element) so you are able to work with them just like with a usual array, furthermore if there are only one element in the resulted array - you can access to it's methods without index e.g.:

```
 $dQ = domQuery\Selector::i($document)->q('.myClass')->q('.mySubClass');
```

domQuery\\Element is a wrapper around DOMElement, but it also includes some useful methods such as text(), innerHTML() and outerHTML(). Also you are able to run q() method from the domQuery\\Element element and select it's child elements.

Examples
--------

[](#examples)

```
$doc = '

    class demo

div class="notMe"
div class="myClass"
span class="myClass"

        Here goes parent text of the class!

            here is sub element!

';

// 1. Length and text()

// get the length

$els = domQuery\Selector::i($doc)->q('.myClass');
echo "count is: ".$els->length(); // 2 , there are two elements (DIV and SPAN) with class 'myClass'
echo "\n";

if($els->length()) {
    foreach($els as $el) {
        echo $el->text()."\n"; // echo the text of each element: 1 - div class="myClass", 2 - span class="myClass"
    }
    echo "\n";
}

// 2. Nested selectors

// let's select P element with the id = idSubElement

// there are two ways to do it:

$els = domQuery\Selector::i($doc)->q('.parentClass #idSubElement');

// or

$els = domQuery\Selector::i($doc)->q('.parentClass')->q('#idSubElement');

echo trim($els[0]->text()); // echo trimmed text "here is sub element!"
```

In addition
-----------

[](#in-addition)

List of jQuery's selectors:

Powerful jQuery's functionality implementation:

... and a lot of other different jQuery's selectors implementations on php :)

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/97cfa9bd6b59333d0d661e14f494f8bb1496a8fc7ca42c9802b955cb94f9b6b4?d=identicon)[rudestan](/maintainers/rudestan)

---

Top Contributors

[![rudestan](https://avatars.githubusercontent.com/u/696823?v=4)](https://github.com/rudestan "rudestan (1 commits)")

### Embed Badge

![Health badge](/badges/rudestan-domquery/health.svg)

```
[![Health](https://phpackages.com/badges/rudestan-domquery/health.svg)](https://phpackages.com/packages/rudestan-domquery)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
