PHP code example of grepper / grepper-php

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

    

grepper / grepper-php example snippets






$grepper = new \Grepper\GrepperClient('your_api_key_here');
$answers = $grepper->answers->search([
    'query' => 'javascript loop array backwords'
]);
print_r($answers);

// set up your tweaked Curl client
$curl = new \Grepper\HttpClient\CurlClient();
$curl->setTimeout(10); // default is \Grepper\HttpClient\CurlClient::DEFAULT_TIMEOUT
$curl->setConnectTimeout(5); // default is \Grepper\HttpClient\CurlClient::DEFAULT_CONNECT_TIMEOUT

echo $curl->getTimeout(); // 10
echo $curl->getConnectTimeout(); // 5

// tell Grepper to use the tweaked client
\Grepper\ApiRequestor::setHttpClient($curl);

// use the Grepper API client as you normally would

// set up your tweaked Curl client
$curl = new \Grepper\HttpClient\CurlClient([CURLOPT_PROXY => 'proxy.local:80']);
// tell Grepper to use the tweaked client
\Grepper\ApiRequestor::setHttpClient($curl);

\Grepper\Grepper::setLogger($logger);

$answers = $grepper->answers->search([
    'query' => 'js loop',
]);
echo $answers->getLastResponse()->headers['Request-Id'];

\Grepper\Grepper::setCABundlePath("path/to/ca/bundle");

\Grepper\Grepper::setMaxNetworkRetries(2);
bash
composer