PHP code example of aleszatloukal / google-search-api
1. Go to this page and download the library: Download aleszatloukal/google-search-api library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?phprequire_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
aleszatloukal / google-search-api example snippets
$googleSearch = new GoogleSearchApi(); // initialize
$results = $googleSearch->getResults('some phrase'); // get first 10 results for query 'some phrase'
namespaceApp\Http\Controllers;
useApp\Http\Controllers\Controller;
useAlesZatloukal\GoogleSearchApi\GoogleSearchApi;
classGoogleSearchControllerextendsController{
publicfunctionindex(){
$googleSearch = new GoogleSearchApi(); // initialize
$results = $googleSearch->getResults('some phrase'); // get first 10 results for query 'some phrase'//
}
}
$googleSearch = new GoogleSearchApi(); // initialize
$results = $googleSearch->getResults('some phrase'); // get first 10 results for query 'some phrase'
$info = $googleSearch->getSearchInformation(); // get search information
$parameters = array(
'start' => 10, // start from the 10th results,'num' => 10// number of results to get, 10 is maximum and also default value
);
$googleSearch = new GoogleSearchApi(); // initialize
$results = $googleSearch->getResults('some phrase', $parameters); // get second 10 results for query 'some phrase'
$googleSearch = new GoogleSearchApi(); // initialize
$results = $googleSearch->getResults('some phrase'); // get first 10 results for query 'some phrase'
$rawResults = $googleSearch->getRawResults(); // get complete response from Google
$googleSearch = new GoogleSearchApi(); // initialize
$results = $googleSearch->getResults('some phrase'); // get first 10 results for query 'some phrase'
$noOfResults = $googleSearch->getTotalNumberOfResults(); // get total number of results (it can be less than 10)
$googleSearch = new GoogleSearchApi(); // initialize
$googleSearch->setEngineId('someEngineId'); // sets the engine ID
$googleSearch->setApiKey('someApiId'); // sets the API key
$results = $googleSearch->getResults('some phrase'); // get first 10 results for query 'some phrase'
/config/googlesearchapi.php
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.