views:

31

answers:

1

Hey Guys

How do I extract current top 10 twitter trends using CURL. All the php tutorials I found seem to use the old twitter urls which have since changed..

Here is a new url I'm struggling with, the new date at the top seems to throw it http://search.twitter.com/trends/current.json

Any ideas how to echo the values?

e.g. output is

stdClass Object ( [trends] => stdClass Object ( [2010-07-03 15:00:00] => Array ( [0] => stdClass Object ( [name] => Mick Jagger [query] => Mick Jagger ) [1] => stdClass Object ( [name] => Leonardo DiCaprio [query] => Leonardo DiCaprio ) [2] => stdClass Object ( [name] => Lionel Messi [query] => Lionel Messi ) [3] => stdClass Object ( [name] => Maradona pelado [query] => Maradona pelado ) [4] => stdClass Object ( [name] => Lizzie McGuire Movie [query] => Lizzie McGuire Movie ) [5] => stdClass Object ( [name] => Thomas Muller [query] => Thomas Muller ) [6] => stdClass Object ( [name] => Gol Anulado [query] => Gol Anulado ) [7] => stdClass Object ( [name] => Serena Williams [query] => Serena Williams ) [8] => stdClass Object ( [name] => Felipe Melo [query] => Felipe Melo ) [9] => stdClass Object ( [name] => Last Airbender [query] => Last Airbender ) ) ) [as_of] => 1278168745 ) 
A: 

You can use json_decode to parse that source. This should work:

$trends = file_get_contents("http://search.twitter.com/trends/current.json");

print_r(json_decode($trends));
Pekka
ok that works but do you know how to echo the values?
Webby
Easy: $result = json_decode($trends); foreach ($result->trends as $timestamp => $item) { echo $item->name; }
igorw