Thursday, October 22, 2009

Google search text code using php

The  following lines of code will provide search results using the google search API.
   

    //search text to be passes
    $search_text = "katharnavas";
    $url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=".$search_text;

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $results = curl_exec($ch);
    curl_close($ch);

    // The results will be in json encoded format so do a decode
    $json = json_decode($results);
    print_r($json);

No comments:

Post a Comment