Google trends php script
This code is used for get the keywords from the Google HotTrens.U can use the grabtrends() to get the curerent trends words. it return an array of keywords.You can change the $url to get coountry specific keywords ex: $url = “http://www.google.co.in/trends/hottrends”; gives the INDIAN keywords.
You just need to include the following code wereever you want and call the function.
<?php
/*
This code is used for get the keywords from the
Google HotTrens.U can use the grabtrends() to get
the curerent trends words. it return an array of keywords
u can change the $url to get coountry specific keywords
ex: $url = "http://www.google.co.in/trends/hottrends";
gives the INDIAN keywords
*/
//---- this function returns the keywords---
function grabtrends()
{
$url = "http://www.google.com/trends/hottrends";
global $trendurl;
$url=$trendurl;
$arr = curlgrab($url);
$pattern = '|&sa=X">(.*?)</a>|';
$matches = null;
preg_match_all( $pattern, $arr['page'], $matches );
return $matches[1]; // output is an array of key words
}
//---- functio to get data from a website--/
function curlgrab( $url, $ch = null ) {
if( $ch != null ) {
curl_setopt( $ch, CURLOPT_URL, $url );
}
else
{
$ch = curl_init( $url );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_COOKIEJAR, 'cookies.txt' );
curl_setopt( $ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01;Windows NT 5.0)" );
}
$arr[ 'ch' ] = $ch;
$arr[ 'page' ] = curl_exec( $ch );
return $arr;
}
?>
To test this code use this
// include the above code
$out=grabtrends();
echo '<h2>Google Trends Keywords</h2>';
foreach($out as $keyword)
echo "<h3>".$keyword."</h3>";




