google search console api php code example
Example: how to search google php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href='http://fonts.googleapis.com/css?family=Yanone+Kaffeesatz' rel='stylesheet' type='text/css'>
<title>Google Search Results using PHP</title>
</head>
<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" />
</form>
<?php
$search = $_GET['results'];
if(isset($_GET['results']) && $_GET['results'] != "")
{
echo "<br />Your Search Result Array:<br /><br />";
$url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&"
. "q=".str_replace(' ', '%20', $_GET['results']);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, 'http://www.google.com');
$body = curl_exec($ch);
curl_close($ch);
$json = json_decode($body);
print_r($json);
}
?>
</body>
</html>