PHP code example of dobron / search-query-parser

1. Go to this page and download the library: Download dobron/search-query-parser 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/ */

    

dobron / search-query-parser example snippets




$parser = new dobron\SearchQueryParser\Parser([
  'keywords' => 'site,title,inurl'
]);
$result = $parser->parse('site:en.wikipedia.org/ title:Slovakia "cities and towns" -education inurl:wiki/');

echo json_encode($result, JSON_PRETTY_PRINT);

var_dump($result->getQueries());



$parser = new dobron\SearchQueryParser\Compiler([
    // field, value
    ['site', 'en.wikipedia.org/'],

    // field, value
    ['title', 'Slovakia'],

    // value (array or string)
    [['cities and towns']],

    // or:
    // value, negate
    // ['cities and towns', false],

    // field, value, operator, negate
    [null, 'education', '=', true],

    // field, value, operator
    ['inurl', 'wiki/', '=']
]);

echo $parser->compile();
shell
php vendor/bin/phpunit --testdox tests