Source for file Google.php
Documentation is available at Google.php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 2004 Jon Wood |
// +----------------------------------------------------------------------+
// | This source file is subject to version 3.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available through the world-wide-web at the following url: |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Jon Wood <jon@jellybob.co.uk> |
// +----------------------------------------------------------------------+
* A PHP implementation of the Google Web API (http://www.google.com/apis/)
* To use this package you will need to register for a search key.
* @author Jon Wood <jon@jellybob.co.uk>
* @package Services_Google
* @copyright Jon Wood, 2004
* The key to use for queries.
* The object being used for queries.
* The last query to be made.
private $_lastQuery = "";
* The current index which has been reached.
* The last resultset retrieved.
* An array of options to be applied to queries.
* @param string $key The web services key provided by Google.
$this->_soapClient = new SoapClient ('http://api.google.com/GoogleSearch.wsdl');
* @param array $options An array of options
foreach($options as $key => $value) {
* Setup up a search to be run.
* Once you've run this method, you need to call fetch() to get results.
* You can set search options with the queryOptions variable.
* @param string $query The query string to use.
* @see Services_Google::fetch()
* @see Services_Google::$queryOptions
public function search($query)
$this->_lastQuery = $query;
* Fetch results from a search.
* This method will return a GoogleSearchResult object, or false if no
* results were found, or the limit has been reached.
* @return GoogleSearchResult|false
* @see http://api.google.com/GoogleSearch.wsdl
* @see Services_Google::search()
if ($this->_index == $this->_result->endIndex - 1 ) {
if (count($this->_result->resultElements )) {
return $this->_result->resultElements [$this->_index - $this->_result->startIndex ];
* Returns the number of results for the current query.
if (is_null($this->_result) && !empty ($this->_lastQuery)) {
return $this->_result->estimatedTotalResultsCount;
if (is_null($this->_result) && !empty ($this->_lastQuery)) {
return $this->_result->searchTime;
* Does a spell check using Google's spell checking engine.
* @param string $phrase The string to spell check.
* @return string A suggestion of how the phrase should be spelt.
return $this->_soapClient->doSpellingSuggestion ($this->key, $phrase);
* Gets a cached page from Google's cache.
* @param string $url The page to get.
* @return string The cached page.
$result = $this->_soapClient->doGetCachedPage ($this->key, $url);
* Runs a query when neccesary
private function runQuery ()
$this->_result = $this->_soapClient->doGoogleSearch (
if ($this->_index == $this->_result->endIndex - 1 ) {
if ($this->_index >= $this->_result->estimatedTotalResultsCount - 1 ) {
return (bool) count($this->_result->resultElements );
if ($this->_result->startIndex < 10 ) {
return $this->_result->resultElements [$this->_index];
return $this->_result->resultElements [$this->_index - ($this->_result->startIndex - 1 )];
Documentation generated on Mon, 11 Mar 2019 15:17:56 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|