PHP
  Home arrow PHP arrow Page 3 - Create Your Own Search Engine with PHP and...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Create Your Own Search Engine with PHP and Google Web Services
By: Ahm Asaduzzaman
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 49
    2003-02-12

    Table of Contents:
  • Create Your Own Search Engine with PHP and Google Web Services
  • Interacting with Google's Web Services
  • Walkthrough Example
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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>

    More PHP Articles
    More By Ahm Asaduzzaman


     

    PHP ARTICLES

    - 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
    - PHP Frontend to ImageMagick
    - Using PEAR's mimeDecode Module
    - Incoming Mail and PHP







    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek