PHP code example of wikitext / query

1. Go to this page and download the library: Download wikitext/query library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wikitext / query example snippets


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/')
]);

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

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

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

Wikitext\Query find(string $selector)

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

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

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

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

string getText()

array getItems()

boolean isEmpty()

int count()

Wikitext\Query first()

Wikitext\Query last()

Wikitext\Query eq(int $index)

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

count($query); // x

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

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