Skip to content

Instantly share code, notes, and snippets.

@ridho1991
Created March 10, 2015 02:03
Show Gist options
  • Save ridho1991/be5337186eee33721d60 to your computer and use it in GitHub Desktop.
Save ridho1991/be5337186eee33721d60 to your computer and use it in GitHub Desktop.
API Google Trends
<?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];
}
?>
@sfakir
Copy link

sfakir commented Mar 10, 2015

Better don't use hard coded urls in your code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment