Tuesday, 27 January 2015

Google trends api php - How to get hot trends

Google trends api php - How to get hot trends


Google Trends is a public web facility of Google Inc., based on Google Search, that shows how often a particular search-term is entered relative to the total search-volume across various regions of the world, and in various languages. 
From: en.wikipedia.org/wiki/Google_Trends


Use following code to get the hot trends from google.
  
try {            
            $url='http://www.google.com/trends/hottrends/atom/hourly';                        
            $client = new Zend_Http_Client($url);
            $response = $client->request('GET');
            $jsonData = ($response->getBody());
            echo 'Google Trends';            
            preg_match_all('/(.*)<\/a>/', $jsonData, $trends);
            /** preg_match_all('/(.*)<\/a>/', $jsonData, $trends);**/
             foreach($trends[0] as $trend) {
                echo "{$trend}";
                }

        } catch (Exception $e) {
            echo 'Error' . $e->getMessage();
        }