Sunday 26 February 2017

How to get hot trends Using Google trends api php

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. 

Use following code to get the hot trends from google. 
try {            
            $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();