PHP code example of searchdata / php-sdk

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

    

searchdata / php-sdk example snippets


sudo apt-get install php-curl

composer 

 

chdataSDK\SearchdataGoogleSearch;
use SearchdataSDK\SearchdataLocations;

$googleSearch = new SearchdataGoogleSearch('YOUR_API_KEY');
$locationsAPI = new SearchdataLocations();

try {
    $locations = $locationsAPI->execute('New York', 1)['body'];

    $googleSearch->set_q('test');
    $googleSearch->set_device('mobile');
    $googleSearch->set_lr('lang_en|lang_ar');
    $googleSearch->set_location($locations[0]['location']);

    $response = $googleSearch->execute();
    echo json_encode($response['body']);
} catch (Exception $e) {
    echo $e->getMessage();
}

 

chdataSDK\SearchdataGoogleSearch;
use SearchdataSDK\SearchdataLocations;

$googleSearch = new SearchdataGoogleSearch('YOUR_API_KEY');
$locationsAPI = new SearchdataLocations();

try {
    $locations = $locationsAPI->execute('New York', 1)['body'];

    $response = $googleSearch->executeRaw([
        'q' => 'test',
        'device' => 'mobile',
        'lr' => 'lang_en|lang_ar',
        'location' => $locations[0]['location']
    ]);
    echo json_encode($response['body']);
} catch (Exception $e) {
    echo $e->getMessage();
}