PHP code example of radowoj / searcher
1. Go to this page and download the library: Download radowoj/searcher 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/ */
radowoj / searcher example snippets
use GuzzleHttp\Client as GuzzleClient;
use Radowoj\Searcher\SearchProvider\Bing;
use Radowoj\Searcher\SearchProvider\Google;
use Radowoj\Searcher\Searcher;
$client = new GuzzleClient();
//
// If you want to use Google
//
$searchProvider = new Google(
$client,
'your-google-api-key',
'your-custom-search-cx-value-set-in-google-account-panel'
);
//
// Or if you want to use Bing
//
$searchProvider = new Bing(
$client,
'your-bing-api-key'
);
//
// Rest of the necessary code is the same regardless of search provider used
//
$searcher = new Searcher($searchProvider);
$results = $searcher->query('"nyan cat"')
->limit(10)
->offset(0)
->find();
//Array access
var_dump(($results[5])->toArray());
//Traversable
foreach($results as $result){
var_dump($result->toArray());
}
//Countable
var_dump(count($results));
//...and total-result-countable ;)
var_dump($results->totalCount());