PHPackages                             scarletsfiction/scarletsquery - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. scarletsfiction/scarletsquery

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

scarletsfiction/scarletsquery
=============================

ScarletsQuery is a high performance HTML or XML query selector/parser for PHP that almost like jQuery.

1.0.3(7y ago)21081MITPHPPHP &gt;=5.6

Since Aug 15Pushed 7y ago1 watchersCompare

[ Source](https://github.com/ScarletsFiction/ScarletsQuery)[ Packagist](https://packagist.org/packages/scarletsfiction/scarletsquery)[ RSS](/packages/scarletsfiction-scarletsquery/feed)WikiDiscussions master Synced yesterday

READMEChangelog (3)DependenciesVersions (4)Used By (0)

[![](https://camo.githubusercontent.com/37988801774c2a675a4e0b1ba26feab98faca9d9fcfe3d15dc35d6a7f9f2a12c/687474703a2f2f616e69736963732e73747265616d2f6173736574732f696d672f737570706f72742d62616467652e706e67)](https://www.patreon.com/stefansarya)

[![Written by](https://camo.githubusercontent.com/d83f94076638b5add826e553cceddd09a3b0b279b56bb84a25a1a6b3aa5114d9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5772697474656e25323062792d536361726c65747346696374696f6e2d2532333165383766662e737667)](https://github.com/ScarletsFiction/)[![Software License](https://camo.githubusercontent.com/1a2e0606685ce00663bf829868f794fd3fc9c86f8d80cae324734129e0723a58/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d627269676874677265656e2e737667)](LICENSE)[![Build Status](https://camo.githubusercontent.com/eef7537ec971810f8e649def03a1cbbfd09dacf12046a7a2be8749a9873acfb3/68747470733a2f2f6170692e7472617669732d63692e6f72672f536361726c65747346696374696f6e2f536361726c65747351756572792e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/ScarletsFiction/ScarletsQuery)[![Tweet](https://camo.githubusercontent.com/cb820a0ecc9645168e33b03925d7f14691262ddbaeaf66a0a91697803d0cba2d/68747470733a2f2f696d672e736869656c64732e696f2f747769747465722f75726c2f687474702f736869656c64732e696f2e7376673f7374796c653d736f6369616c)](https://twitter.com/intent/tweet?text=ScarletsQuery%20is%20a%20high%20performance%20HTML%20or%20XML%20query%20selector/parser%20for%20PHP%20that%20almost%20like%20jQuery&url=https://github.com/ScarletsFiction/ScarletsQuery&via=github&hashtags=scarlets,dom,parser,query,php)

ScarletsQuery
=============

[](#scarletsquery)

ScarletsQuery is a high performance HTML or XML query selector/parser for PHP that almost like jQuery.

Installation instruction
------------------------

[](#installation-instruction)

Clone/download this repository and include `ScarletsQuery.php`

### Install with composer

[](#install-with-composer)

> composer require scarletsfiction/scarletsquery

Available Methods
-----------------

[](#available-methods)

This library query selector is designed like jQuery's queryselector.
But there are different method to obtain the data.

### MarkupLanguage

[](#markuplanguage)

This class will handle every selector query and parse Markup Language.

> MarkupLanguage::parseText($string);

Parse HTML/XML to structured array as `MarkupLanguageElementCollection`

### MarkupLanguageElementCollection

[](#markuplanguageelementcollection)

This class have a collection of Element Tree, you can also obtain the value just like an array `$collection[0]` and it will return `MarkupLanguageElement`.

> $dom-&gt;length;

Return length of Element Collection

> $dom-&gt;view;

Return raw array of the Element Collection

> $dom-&gt;selector($query);

Return the result as `MarkupLanguageElementCollection`

> $dom-&gt;parent();

Return parent of all result as `MarkupLanguageElementCollection`

> $dom-&gt;content($index = false);

Return content of all result as `Array`If `$index` specified, it will return the content as `String`

### MarkupLanguageElement

[](#markuplanguageelement)

This class have a collection of Element Tree, you can also obtain the value just like an array `$collection[0]` and it will return `MarkupLanguageElement`.

> $dom-&gt;view;

Return raw array of the Element

> $dom-&gt;selector($query);

Return the result as `MarkupLanguageElement`

> $dom-&gt;parent();

Return the element's parent `MarkupLanguageElement`

> $dom-&gt;hasClass($class);

Return `true` if found and vice-versa

> $dom-&gt;next($jump = 1);

Return the next sibling element as `MarkupLanguageElement`

> $dom-&gt;content();

Return the content as `String`

> $dom-&gt;attr($property);

Return element property as `String` or `null` if not found

Example Usage
-------------

[](#example-usage)

```

    Alex
    1a

    Steven
    2b

    Elisabeth
    3c

    Luffy
    4d

```

And below is the PHP script

```
$html = file_get_contents('sample.html');
$dom = Scarlets\Library\MarkupLanguage::parseText($html);

// Select element that have 'name' id and get these content
$dom->selector('#name')->content();
/* Output
    Array
    (
        [0] => Alex
        [1] => Elisabeth
        [2] => Luffy
    )
*/

/*
  1. Select element that have 'ul' tag
  2. Select the child with '3' id
  3. Select the element before it { next(-1) }
  4. Get the content
*/
$dom->selector('ul #3')[0]->next(-1)->content();
/* Output
    Elisabeth
*/

// Select 'ul' tag and the child with 'li' tag
$contents = $dom->selector('ul li');

// Iterate over the result
for ($i=0; $i < $contents->length; $i++) {

    // Check if the element has 'profile' class
    if($contents[$i]->hasClass('profile')){

        // Select the child with 'span' tag
        // And get the second content
        print_r($contents[$i]->selector('span')->content(1));
    }
}
/* Output
    3c
*/
```

Contribution
------------

[](#contribution)

If you want to help in ScarletsQuery, please fork this project and edit on your repository, then make a pull request to here.

Keep the code simple and clear.

License
-------

[](#license)

ScarletsQuery is under the MIT license.

Help improve this framework by support the author ＼(≧▽≦)／

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity59

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.

###  Release Activity

Cadence

Every ~117 days

Total

3

Last Release

2593d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b1f8514602bd980243d202d81263e620513484e274b7938725952039360d1b6c?d=identicon)[StefansArya](/maintainers/StefansArya)

---

Top Contributors

[![StefansArya](https://avatars.githubusercontent.com/u/11073373?v=4)](https://github.com/StefansArya "StefansArya (11 commits)")

---

Tags

dom-parserjqueryparsephpselector-queryxmlphpparserhtmldomselectorscarlets

### Embed Badge

![Health badge](/badges/scarletsfiction-scarletsquery/health.svg)

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

###  Alternatives

[sunra/php-simple-html-dom-parser

Composer adaptation of: A HTML DOM parser written in PHP5+ let you manipulate HTML in a very easy way! Require PHP 5+. Supports invalid HTML. Find tags on an HTML page with selectors just like jQuery. Extract contents from HTML in a single line.

1.3k9.4M61](/packages/sunra-php-simple-html-dom-parser)[simplehtmldom/simplehtmldom

A fast, simple and reliable HTML document parser for PHP.

1921.3M14](/packages/simplehtmldom-simplehtmldom)[ressio/pharse

Fastest PHP HTML Parser

8478.4k](/packages/ressio-pharse)[oscarotero/html-parser

Parse html strings to DOMDocument

165.0M1](/packages/oscarotero-html-parser)[zenthangplus/html-dom-parser

A Simple HTML DOM parser written in PHP let you manipulate HTML in a easy way with CSS Selector.

1216.7k](/packages/zenthangplus-html-dom-parser)[hexydec/htmldoc

A token based HTML document parser and minifier. Minify HTML documents including inline CSS, Javascript, and SVG's on the fly. Extract document text, attributes, and fragments. Full test suite.

2610.3k3](/packages/hexydec-htmldoc)

PHPackages © 2026

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