Skip to content

Instantly share code, notes, and snippets.

@ridho1991
Created March 10, 2015 12:32
Show Gist options
  • Save ridho1991/e3e922cea09d838524db to your computer and use it in GitHub Desktop.
Save ridho1991/e3e922cea09d838524db to your computer and use it in GitHub Desktop.
Google Keyword Suggest
<?php
function google_suggest($query) {
$xml = simplexml_load_file ( utf8_encode ( "http://www.google.com/complete/search?output=toolbar&hl=en&q=" . $query . "" ) );
$suggest=array();
if (@$xml) {
foreach ( $xml->children () as $child ) {
foreach ( $child->suggestion->attributes () as $data ) {
$suggest [] = $data;
}
}
return $suggest;
}
}
?>
<html>
<head>
<meta charset="UTF-8">
<title>Google Keyword Suggest</title>
</head>
<body>
<form action="keyword.php" method="get">
<input type="text" id="q" name="q" value="" placeholder="Enter text here"/>
<button type="submit" value="" >Submit</button>
</form>
</body>
</html>
<html>
<head>
<title><?php echo $_GET['q'];;?></title>
<meta charset="UTF-8">
</head>
<body>
<?php
ini_set('max_execution_time', 0);
ini_set('memory_limit', '999M');
require_once('api.php');
$q=$_GET['q'];
$google_key=google_suggest($q);
foreach($google_key as $key){
echo $key.'<br>';
}
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment