Location: PHPKode > scripts > Google Developer API > google-developer-api/example.php
<?php
require_once 'Google_API.php';

/**
 *  EXAMPLE of how the Google_API can be applied
 *
 *  Use the Google_API to find out where a specific website is listed within
 *  a set of results for a specific search query
 *
 */
function findRanking($domain, $query, $maxLimit = 120) {
    $google = new Google_API('YOURveryOWNgoogle.comAPIkey');
    $apiParams = array(
                'start' => 0,               // the point in the search results should Google start
                'maxResults' => 10,         // the number of search results (max 10)
                'filter' => true,           // should the results be filtered?
                'restrict' => '',
                'safeSearch' => false,
                'lr' => '',
                'ie' => '',
                'oe' => ''
        );

    for ( $page = 0; $page <= ceil($maxLimit / 10); $page++ ) {
        $apiParams['start'] = ($page * 10) + 1;
        if ( !PEAR::isError($results = $google->Search($query, $apiParams)) ) {
            foreach ( $results->resultElements as $result ) {
                ++$position;
                if ( preg_match('/'.$domain.'/', $result->URL) ) {
                    return $position;
                }
            }
        }
    } 
    return false;
}

$google = new Google_API('YOURveryOWNgoogle.comAPIkey');
$useExample = 'cache';

switch ( strtoupper($useExample) ) {
case 'CACHE':
    echo $google->GetCachedPage('www.kudosonline.com.au');
    break;

case 'CUSTOM':
    if ( $position = findRanking('mydomain.com.au', 'content management melbourne site:au') ) {
        echo 'Found at position ['.$position.']';
    } else {
        echo 'Not Found in Results';
    }
    break;

case 'SPELLING':
    echo $google->SpellingSuggestion('kudosi online');
    break;
}
?>
Return current item: Google Developer API