Home arrow PHP arrow Page 3 - Create Your Own Search Engine with PHP and Google Web Services
PHP

Create Your Own Search Engine with PHP and Google Web Services


In this article, Ahm shows us how to retrieve search results from Google via Web Services, effectively creating our own search engine.

Author Info:
By: Ahm Asaduzzaman
Rating: 4 stars4 stars4 stars4 stars4 stars / 55
February 12, 2003
TABLE OF CONTENTS:
  1. · Create Your Own Search Engine with PHP and Google Web Services
  2. · Interacting with Google's Web Services
  3. · Walkthrough Example
  4. · Conclusion

print this article
SEARCH DEVARTICLES

Create Your Own Search Engine with PHP and Google Web Services - Walkthrough Example
(Page 3 of 4 )

<html>
<head><basefont face="Verdana" size="2"></head>
<body>
<?php

if (!$_POST['queryStr'])
{
?>
  <h2>MyGoogle Search Engine</h2>
  <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
  Type search term: <input type="text" name="queryStr">
  </form>
<?
}
else
{
  // include the class from NuSOAP
  include("nusoap.php");
  
  // create a instance of the SOAP client object
  $soapclient = new soapclient("http://api.google.com/search/beta2");
  
  // uncomment the next line to see debug messages
  // $soapclient->debug_flag = 1;
  
  // prepare an array of input parameters to be passed to the remote   procedure
// doGoogleSearch()
  $params = array(
     'Googlekey' => 'gs8f1fJQFHJfBmgmratlW5z3nTQV0ts8', // Google license
  // key
     'queryStr' => $_POST['queryStr'],  // search term that was being typed
     'startFrom' => 0,               // start from result n
     'maxResults' => 10,              // show a total of 10 results
     'filter' => true,               // remove similar results
     'restrict' => '',               // restrict by topic
     'adultContent' => true,        // remove adult links from search result
     'language' => '',              // restrict by language
     'iencoding' => '',             // input encoding
     'oencoding' => ''             // output encoding
  );
  
/* invoke the method on the Googles server. The call() method accept four arguments- name of the remote procedure to be invoked, an array of arguments for the remote procedure, namespace and SOAP action */

$MyResult = $soapclient->call("doGoogleSearch", $params, "urn:GoogleSearch", "urn:GoogleSearch");

/* Uncomment next line, if you want to see the SOAP envelop, which is forwarded to Google server, It is important to understand the content of SOAP envelop*/

// echo '<xmp>'.$soapclient->request.'</xmp>';

/* Uncomment next line, if you want to see the SOAP envelop, which is received from Google server. It is important to understand the SOAP packet forwarded from Google Server */

// echo '<xmp>'.$soapclient->response.'</xmp>';
  
// Print the results of the search
  if ($MyResult['faultstring'])
  {
?>
    <h2>Error Report</h2>
    <? echo $MyResult['faultstring'];?>
<?  
  }
  else
  {
?>
<h2>MyGoogle Search Results</h2>
Your search for <b><?=$MyResult['searchQuery']?></b> produced <?=$MyResult['estimatedTotalResultsCount']?> hits.
    <br>
    
<?   $i=1;
    if (is_array($MyResult['resultElements']))
    { echo "<table border=0 cellspacing=2 cellpadding=2>";
      foreach ($MyResult['resultElements'] as $r)
      {
        echo "<tr><td>[$i] <a href=" . $r['URL'] . ">" . $r['title'] . "</a>";
        echo $r['snippet'] . "(" . $r['cachedSize'] . ")</td></tr>";
        $i++;
      }
    }
    $i=1;
?>
    </table>
<?
  }
}
?>
</body>
</html>

blog comments powered by Disqus
PHP ARTICLES

- Removing Singletons in PHP
- Singletons in PHP
- Implement Facebook Javascript SDK with PHP
- Making Usage Statistics in PHP
- Installing PHP under Windows: Further Config...
- File Version Management in PHP
- Statistical View of Data in a Clustered Bar ...
- Creating a Multi-File Upload Script in PHP
- Executing Microsoft SQL Server Stored Proced...
- Code 10x More Efficiently Using Data Access ...
- A Few Tips for Speeding Up PHP Code
- The Modular Web Page
- Quick E-Commerce with PHP and PayPal
- Regression Testing With JMeter
- Building an Iterator with PHP

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials