PHP code example of floor9design / search-string-parser

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

    

floor9design / search-string-parser example snippets

 php
// Instantiate 
$ssp = new SearchStringParser(new ParserSimple);
// run a search: 
$string = 'some search terms "including literals enclosed in quotes"';
$array = $ssp->parse($string);
 php
array(
    0 => 'including literals enclosed in quotes',
    1 => 'some',
    2 => 'search',
    3 => 'terms'
);
 php
// Instantiate 
$ssp = new SearchStringParser(new ParserSimple);
// run a search: 
$complex = array(
            0 => 'hello world',
            1 => 'foo',
            2 => 'bar "literal string"',
            3 => 3,
            4 => -19.27
        );
$array = $ssp->parse($complex);
 php
array(
    0 => 'literal string',
    1 => 'hello',
    2 => 'world',
    3 => 'foo',
    4 => 'bar',
    5 => '3',
    6 => '-19.27'
);
 php
// Instantiate 
$ssp = new SearchStringParser(new ParserSimple);
// run a search: 
$string = 'some "search terms" Pincluding literals enclosed in another letterP';
$array = $ssp->parse($string);
 php
array(
    0 => 'including literals enclosed in another letter',
    1 => 'some',
    2 => '"search',
    3 => 'terms"'
);
 php
 // we are in the middle of the code, and the object has already been instantiated as above:
  $string = 'some input text "including literals enclosed in quotes"';
 $array = $ssp->parse($string);
  // ... I'll now skip to the relevant part of zend - I assume you can write a query:
  foreach($array as $keyword) {
    $select->orWhere('data_table LIKE ?', "%$keyword%")
 }
 
 bash
$ phpunit --bootstrap vendor/autoload.php tests/