tags:

views:

60

answers:

1

Can you give me a php script who return the firts 3 trending topic of twitter? thanks

+2  A: 

I'm not sure you should be asking people to write code for you, but anyway, here you are.

<?php

$request    = file_get_contents( 'http://search.twitter.com/trends/current.json' );
$json       = json_decode( $request, true );
$trends     = $json[ 'trends' ];
$keys       = array_keys( $trends );
$trends     = $trends[ $keys[ 0 ] ];
$trends     = array(

     $trends[ 0 ][ 'name' ],
     $trends[ 1 ][ 'name' ],
     $trends[ 2 ][ 'name' ]

);
Simon
If you want an associative array out of `json_decode`, you can make the second paramater `true` instead of getting the object and then casting it.
Charles
+1. Forgot about that parameter :)
Simon