How to get keyword suggestions on web page via google, bing, yahoo, amazone by JSOn

Authors: CodeToday | PHP Code | Views: 1072 | Posted: 03 AM: 09/12/2017

If you want to display keyword suggestions on your website then this is the solution, input source is the keyword you need to suggest

Here I will guide you to display keyword suggestions according to the current popular tools such as google, bing, yahoo, amazone. These sources will be exported to you as json code. Your job is to get that data on and display it

Below is a list of links for keyword suggestion

Bing:      http://api.bing.net/osjson.aspx?FORM=OPERAS&Market=ja&Query=[keyword]
Yahoo:     http://ff.search.yahoo.com/gossip?output=fxjson&command=[keyword]
Amazone:   http://completion.amazon.com/search/complete?search-alias=aps&client=amazon-search-ui&mkt=1&q=[keyword]
Wikipedia: http://en.wikipedia.org/w/api.php?action=opensearch&search=[keyword]
Google:    http://suggestqueries.google.com/complete/search?output=firefox&client=firefox&hl=en-US&q=[keyword]

The knowledge required in this article

  1. Curl_init()
  2. Json_decode: Convert JSON String to PHP Array

Bootstrap and jQuery Library

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

curl_init()

<?
function curlGet($url){
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
	curl_setopt($ch, CURLOPT_HTTPGET, 1 );
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION , 1 );
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION , 1 );
	curl_setopt($ch, CURLOPT_URL, $url );
	curl_setopt($ch, CURLOPT_REFERER, $ref );
	curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);     
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
	$data = curl_exec($ch);
	$data = json_decode($data,true); // Json Decode
	curl_close($ch);
	return $data;
}
?>

This function takes the data and json_decode

INDEX.PHP source code

<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>How to get keyword suggestions on web page</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h1>How to get keyword suggestions on web page</h1>
<ul class="nav nav-tabs">
  <li class="active"><a data-toggle="tab" href="#home">Bing</a></li>
  <li><a data-toggle="tab" href="#menu1">Google</a></li>
  <li><a data-toggle="tab" href="#menu2">Yahoo</a></li>
  <li><a data-toggle="tab" href="#menu3">Wikipedia</a></li>
  <li><a data-toggle="tab" href="#menu4">Amazone</a></li>
</ul>

<div class="tab-content">
  <div id="home" class="tab-pane fade in active">
	  <?
	  $bing = curlGet('http://api.bing.net/osjson.aspx?FORM=OPERAS&Market=ja&Query=ceo');
	  echo '<p>';
	  echo '<ul>';
		  foreach($bing[1] as $keyword) {
			echo '<li>'.$keyword.'</li>';
		  }
	  echo '</ul>';
	  echo '</p>';
	  ?>
  </div>
  <div id="menu1" class="tab-pane fade">
	  <?
	  $google = curlGet('http://suggestqueries.google.com/complete/search?output=firefox&client=firefox&hl=en-US&q=ceo');
	  echo '<p>';
	  echo '<ul>';
		  foreach($google[1] as $keyword) {
			echo '<li>'.$keyword.'</li>';
		  }
	  echo '</ul>';
	  echo '</p>';
	  ?>  
  </div>
  <div id="menu2" class="tab-pane fade">
	  <?
	  $google = curlGet('http://ff.search.yahoo.com/gossip?output=fxjson&command=ceo');
	  echo '<p>';
	  echo '<ul>';
		  foreach($google[1] as $keyword) {
			echo '<li>'.$keyword.'</li>';
		  }
	  echo '</ul>';
	  echo '</p>';
	  ?>  
  </div>
  <div id="menu3" class="tab-pane fade">
	  <?
	  $google = curlGet('http://en.wikipedia.org/w/api.php?action=opensearch&search=ceo');
	  echo '<p>';
	  echo '<ul>';
		  foreach($google[1] as $keyword) {
			echo '<li>'.$keyword.'</li>';
		  }
	  echo '</ul>';
	  echo '</p>';
	  ?>  
  </div>
  <div id="menu4" class="tab-pane fade">
	  <?
	  $google = curlGet('http://completion.amazon.com/search/complete?search-alias=aps&client=amazon-search-ui&mkt=1&q=ceo');
	  echo '<p>';
	  echo '<ul>';
		  foreach($google[1] as $keyword) {
			echo '<li>'.$keyword.'</li>';
		  }
	  echo '</ul>';
	  echo '</p>';
	  ?>  
  </div>    
</div>
<?
function curlGet($url){
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
	curl_setopt($ch, CURLOPT_HTTPGET, 1 );
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION , 1 );
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION , 1 );
	curl_setopt($ch, CURLOPT_URL, $url );
	curl_setopt($ch, CURLOPT_REFERER, $ref );
	curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);     
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
	$data = curl_exec($ch);
	$data = json_decode($data,true); // Json Decode
	curl_close($ch);
	return $data;
}
?>
</div>
</body>
</html> 
Keyword example here is "CEO", These tools will rely on their own algorithms to generate appropriate keyword suggestions.

After performing the above steps, the results will be displayed as shown below:



If you have any questions, please leave a message below