Skip to content

PHP code snippet – How to search google ?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href='' rel='stylesheet' type='text/css'>
<title>Google Search Results using PHP</title>

<body style="margin-left:20px;">

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

<label>Enter your search criteria here:</label>
<form method="get" action="">
<input name="results" />
<input type="submit" />


$search = $_GET['results'];
if(isset($_GET['results']) && $_GET['results'] != "")
		echo "<br />Your Search Result Array:<br /><br />";
	$url = ""
		. "q=".str_replace(' ', '%20', $_GET['results']);
	// sendRequest
	// note how referer is set manually
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_REFERER, '');
	$body = curl_exec($ch);
	// now, process the JSON string
	$json = json_decode($body);
	// print out the Array
	// now have some fun with the results...



See also  Python code snippet - How to insert value in admin panel in django?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.