Home

See the related posts

Mysql server version using php function – mysql_get_server_info()    Text file prompt download or force download using php    Number of lines in a file using php    Check Image exists or Not Using php and GD    PHP Warning: Call-time pass-by-reference has been deprecated   

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>";

Home

See the related posts

Mysql server version using php function – mysql_get_server_info()    Text file prompt download or force download using php    Number of lines in a file using php    Check Image exists or Not Using php and GD    PHP Warning: Call-time pass-by-reference has been deprecated   

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment