Get latest Hot-Trends from Google with some simple PHP script

Google Trends LogoIf you run a website it’s essential for you to know about the actual trends on the web, not only to optimize your keywords, but to know what to write about at all. The equation is easy: What people search for is what brings you visitors and visitors are money!

But how to know what’s trendy on the web, if you are not Google yourself?

Fortunately, Google developed Google Trends and a feed with hourly updated hot trends, where you can easily access the actual trends on the web, but who wants to check a website manually every time one wants to get some update. It would be so much smoother with some automatism, but is there an API for the trends? Not yet, but there is another way to fetch the latest Trends. Google itself provides a feed about hourly updated trends on Google.

[ad#Image Header Top]

With some PHP code and a simple regular expression we can get the actual Trends:

< ?php
$url = 'http://www.google.com/trends/hottrends/atom/hourly';
$feed = file_get_contents($url);
 
preg_match_all('/&lt;a.*&gt;<a>(.*)&lt;\/a&gt;/', $feed, $trends);
 
foreach($trends[1] as $trend) {
echo 'Trend: ',$trend,"\n";
}
?>

Here we have some really simple script which only has one job: fetch the trends and echo them to the stdout. I think everyone with PHP experience should understand it and if not I only can say: Learn PHP! 😉

Now, it’s up to you what to do with these trends – feel free to use, change and extend that code. Maybe it helps you with the SEO for your page.

Similar Posts: