Download the PHP package wikitext/query without Composer
On this page you can find all versions of the php package wikitext/query. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package query
Wikitext Query
Wikitext Query is a PHP query object that helps you to crawl through wikitext markup language.
Installation
Installation can be done using Composer to download and install Wikitext Query as well as its dependencies.
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:
Creating a new Query object can be done by passing it the wikitext content.
The Query object will split the wikitext into single lines; alternatively you can also pass it an array with lines yourself:
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.
Please notice! Query actions like next
and prev
always relate back to the initial wikitext.
Documentation
Crawl
Find
Returns a Query object with all lines from the initial wikitext that match the selector.
When you use find on a Query object other than the main object it will filter from that.
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.
When none is found, an empty Query object is returned.
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.
When none is found, an empty Query object is returned.
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.
When none are found, an empty Query object is returned.
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.
When none are found, an empty Query object is returned.
Access
Items in the query object can be accessed in multiple ways.
Get text
Returns the lines of the Query object as a single string (imploded with "\n"").
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.
Is empty
Returns true if the Query has no lines.
Count
Returns the number of lines in a Query.
First
Returns a Query object with the first of line of the Query.
Last
Returns a Query object with the last of line of the Query.
Eq
Returns a Query object with the nth line of the Query.
Match
Matches a regular expression against the wikitext and returns the defined index or the default value.
Countable, ArrayAccess & IteratorAggregate
A Query object can be treated as an array, but will always return its lines as Query objects.
Support
Please file issues here at Github
All versions of query with dependencies
ext-json Version *