07-13-2014, 03:56 AM
Instruction:
Put this up on a file on your server.
Call it like this:
yourscriptname.php?keywords
Put this up on a file on your server.
Call it like this:
yourscriptname.php?keywords
PHP Code:
<?php
function text_between($start,$end,$string) {
if ($start != '') {$temp = explode($start,$string,2);} else {$temp = array('',$string);}
$temp = explode($end,$temp[1],2);
return $temp[0];
}
function getHttp($url)
{
$userAgent = 'Firefox (WindowsXP) - Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6';
// make the cURL request to $target_url
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$html= curl_exec($ch);
if (!$html)
{
echo "<br />cURL error number:" .curl_errno($ch);
echo "<br />cURL error:" . curl_error($ch);
exit;
}
return $html;
}
function gsscrape($keyword) {
$keyword=str_replace(" ","+",$keyword);
global $kw;
$url='http://clients1.google.com/complete/search?hl=en&q='.$keyword;
$data = getHttp($url);
$data=explode('[',$data,3);
$data=explode('],[',$data[2]);
foreach($data as $temp) {
$kw[]= text_between('"','"',$temp);
}
}
# just use yourscriptname.php?keywords
if ($_SERVER['QUERY_STRING']!='') {
gsscrape($_SERVER['QUERY_STRING']);
foreach ($kw as $keyword) {
gsscrape($keyword);
}
}
echo 'Url;Results<br>';
#all results are in array $kw...
foreach($kw as $keyword) {
if ($keyword !='')
{
$url = 'http://www.google.com/search?q='.urlencode($keyword);
$html=getHttp($url);
$abc = str_replace('of about <b>', '', strstr($html, 'of about <b>'));
echo '<a href="'.$url.'">'.$keyword.'</a>;'.substr($abc, 0, strpos($abc, '</b>')).'<br />';
}
}
?>>