Created
March 10, 2015 02:03
-
-
Save ridho1991/be5337186eee33721d60 to your computer and use it in GitHub Desktop.
API Google Trends
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function fetch_trends($country_code) | |
{ | |
$trendsurl = "http://www.google.com/trends/hottrends/atom/hourly?pn=".$country_code.""; | |
$c = curl_init($trendsurl); | |
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); | |
$responsedata = curl_exec($c); | |
curl_close($c); | |
return parse_trend_feed( $responsedata ); | |
} | |
function parse_trend_feed($data) | |
{ | |
preg_match_all('/.+?<a href=".+?">(.+?)<\/a>.+?/',$data,$matches); | |
return $matches[1]; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Better don't use hard coded urls in your code.