google search php

Solutions on MaxInterview for google search php by the best coders in the world

showing results for - "google search php"
Irene
01 Aug 2018
1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2<html xmlns="http://www.w3.org/1999/xhtml">
3<head>
4<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5<link href='http://fonts.googleapis.com/css?family=Yanone+Kaffeesatz' rel='stylesheet' type='text/css'>
6<title>Google Search Results using PHP</title>
7</head>
8
9<body style="margin-left:20px;">
10
11<h1 style="font-family: 'Yanone Kaffeesatz', arial, serif;">This is a demo page which demonstrates how to print out Google Search Results using PHP</h1>
12<h2 style="font-family: 'Yanone Kaffeesatz', arial, serif;">To view this tutorial go to <a href="#" target="_blank">Google Search Results using PHP</a></h2>
13
14
15<label>Enter your search criteria here:</label>
16<form method="get" action="">
17<input name="results" />
18<input type="submit" />
19</form>
20
21
22<?php
23
24$search = $_GET['results'];
25if(isset($_GET['results']) && $_GET['results'] != "")
26	{
27		
28		echo "<br />Your Search Result Array:<br /><br />";
29	
30	$url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&"
31		. "q=".str_replace(' ', '%20', $_GET['results']);
32	
33	// sendRequest
34	// note how referer is set manually
35	$ch = curl_init();
36	curl_setopt($ch, CURLOPT_URL, $url);
37	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
38	curl_setopt($ch, CURLOPT_REFERER, 'http://www.google.com');
39	$body = curl_exec($ch);
40	curl_close($ch);
41	
42	// now, process the JSON string
43	$json = json_decode($body);
44	
45	// print out the Array
46	print_r($json);
47	
48	// now have some fun with the results...
49}
50
51?>
52
53</body>
54</html>
55
56