PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Dave Smith   serpStack PHP Google Search API   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example Usage
Class: serpStack PHP Google Search API
Perform searches on Google using the serpStack API
Author: By
Last change:
Date: 4 years ago
Size: 1,177 bytes


Class file image Download
example usage
serpStack ver 1.0

You must get an API key from
and enter it in the weatherstack.class.php file

//turning off low level notices
error_reporting(E_ALL ^ E_NOTICE);

//instantiate the class
$serp = new serpStack();

//set the end point to use
//serp scraping uses the 'search' endpoint
//we can set it with 'search' or 's' shorthand

//set the query parameter

//optionally set to a safe search

//get the response

//check for errors
if( !empty($serp->errorCode) ){
//error returned
echo $serp->errorCode.': '.$serp->errorText;
//loop through and show specific response data
foreach($serp->response->organic_results as $result){
<h5><a href="<?php echo $result->url;?>"><?php echo $result->title;?></a></h5>
        <div><?php echo $result->snippet;?></div>

//displaying the full response
echo '<pre>';