PHPackages                             wikitext/query - 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. wikitext/query

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

wikitext/query
==============

A query object that helps you crawl through wikitext.

v1.1.1(7y ago)014MITPHPPHP ^7.1

Since Sep 9Pushed 7y ago1 watchersCompare

[ Source](https://github.com/tsoffereins/wikitext-query)[ Packagist](https://packagist.org/packages/wikitext/query)[ Docs](https://github.com/tsoffereins/wikitext)[ RSS](/packages/wikitext-query/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (2)Versions (5)Used By (0)

Wikitext Query
==============

[](#wikitext-query)

Wikitext Query is a PHP query object that helps you to crawl through wikitext markup language.

Installation
------------

[](#installation)

Installation can be done using [Composer](https://getcomposer.org/) to download and install Wikitext Query as well as its dependencies.

```
composer require wikitext/query

```

Usage
-----

[](#usage)

Before you can start to query anything you have to define the selectors that are available. You can create your own, although there is a set of matchers part of this package. All you need to do is add them:

```
Wikitext\Query::addMatchers([
    new Wikitext\Matchers\HeaderMatcher('h1'), // h1, h2, ...
    new Wikitext\Matchers\UnorderedListMatcher(), // ul
    new Wikitext\Matchers\OrderedListMatcher(), // ol
    new Wikitext\Matchers\ListItemMatcher(), // li
    new Wikitext\Matchers\AnchorMatcher(), // a
    new Wikitext\Matchers\RowMatcher(), // hr
    new Wikitext\Matcher('selector', '/regex/')
]);
```

Creating a new Query object can be done by passing it the wikitext content.

```
$query = new Wikitext\Query('wikitext');
```

The Query object will split the wikitext into single lines; alternatively you can also pass it an array with lines yourself:

```
$query = new Wikitext\Query(['line 1', 'line 2', 'line 3']);
```

This initial Query (or main Query) serves as a something like the 'DOM'. Any action you perform on it, or any sub-query will always be related to this original object. This means that a sub-selection will still refer to the line numbers as present in the original wikitext.

The query object shows quite some similarity with jQuery when trying to query its content. Both the methods and the selectors are more or less the same. Each query action returns a new query in order to allow method chaining.

```
$result = $query->find('h1')->next('hr');
```

*Please notice!* Query actions like `next` and `prev` always relate back to the initial wikitext.

Documentation
-------------

[](#documentation)

### Crawl

[](#crawl)

#### Find

[](#find)

Returns a Query object with all lines from the initial wikitext that match the selector.

```
Wikitext\Query find(string $selector)
```

When you use find on a Query object other than the main object it will filter from that.

#### Next

[](#next)

Returns a Query object with the line after the first item in the Query according to the initial wikitext. When the selector is specified it will return the line accordingly.

```
Wikitext\Query next(string $selector = "*")
```

When none is found, an empty Query object is returned.

#### Prev

[](#prev)

Returns a Query object with the line before the first item in the Query according to the initial wikitext. When the selector is specified it will return the line accordingly.

```
Wikitext\Query prev(string $selector = "*")
```

When none is found, an empty Query object is returned.

#### Next all

[](#next-all)

Returns a Query object with the lines after the first item in the Query according to the initial wikitext. When the selector is specified it will return the lines accordingly.

```
Wikitext\Query nextAll(string $selector = "*")
```

When none are found, an empty Query object is returned.

#### Prev all

[](#prev-all)

Returns a Query object with the lines before the first item in the Query according to the initial wikitext. When the selector is specified it will return the lines accordingly.

```
Wikitext\Query prevAll(string $selector = "*")
```

When none are found, an empty Query object is returned.

### Access

[](#access)

Items in the query object can be accessed in multiple ways.

#### Get text

[](#get-text)

Returns the lines of the Query object as a single string (imploded with "\\n"").

```
string getText()
```

#### Get items

[](#get-items)

Returns an array with all the lines in the Query object. The keys of the array will always correspond with their position in the initial wikitext.

```
array getItems()
```

#### Is empty

[](#is-empty)

Returns true if the Query has no lines.

```
boolean isEmpty()
```

#### Count

[](#count)

Returns the number of lines in a Query.

```
int count()
```

#### First

[](#first)

Returns a Query object with the first of line of the Query.

```
Wikitext\Query first()
```

#### Last

[](#last)

Returns a Query object with the last of line of the Query.

```
Wikitext\Query last()
```

#### Eq

[](#eq)

Returns a Query object with the nth line of the Query.

```
Wikitext\Query eq(int $index)
```

#### Match

[](#match)

Matches a regular expression against the wikitext and returns the defined index or the default value.

```
mixed match(string $pattern, int $index = 0, $default = null)
```

### Countable, ArrayAccess &amp; IteratorAggregate

[](#countable-arrayaccess--iteratoraggregate)

A Query object can be treated as an array, but will always return its lines as Query objects.

```
count($query); // x

var_dump($query[3]); // Wikitext\Query

foreach ($query as $line) {
    var_dump($line); // Wikitext\Query
}
```

Support
-------

[](#support)

Please file issues here at Github

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

 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 ~0 days

Total

4

Last Release

2802d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9b9b0e2f4323a09170afd33bc776b3137d64d08282171224a4684ff49b5175f6?d=identicon)[tsoffereins](/maintainers/tsoffereins)

---

Top Contributors

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

---

Tags

parsercrawlerquerywikitextwikipedia

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/wikitext-query/health.svg)

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

###  Alternatives

[illuminated/wikipedia-grabber

Wikipedia/MediaWiki Grabber for Laravel.

477.3k](/packages/illuminated-wikipedia-grabber)[mantoufan/yzhanip

Crawl, match, parse IP or IP range, check if IP or range is in another range. Support IPv4, IPv6, IP Interval, Wildcard and CIDR. Check if IP is Cloudflare node IP, Google bot IP. 爬取，正则匹配，解析 IP 和 IP 范围，检测 IP 或范围是否在另一个范围中。支持 IPv4，IPv6，区间、通配符或 CIDR 表示的 IP 范围。检测 IP 是否是 Cloudflare 节点或 Google 漫游器 IP

541.4k](/packages/mantoufan-yzhanip)[crwlr/robots-txt

Robots Exclusion Standard/Protocol Parser for Web Crawling/Scraping

1125.3k1](/packages/crwlr-robots-txt)[rlacerda83/query-parser

Query parser for lumem

215.0k2](/packages/rlacerda83-query-parser)[laurentvw/scrapher

A web scraper for PHP to easily extract data from web pages

192.5k1](/packages/laurentvw-scrapher)

PHPackages © 2026

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