A Guide to Mobile and Web Technology(LAMP)

Posts tagged ‘google’

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);