json - Twitter Trends PHP -


i trying use http://api.twitter.com/1/trends/current.json?exclude=hashtags having trouble.

so, i'm trying use:

  <?php $init = 'http://api.twitter.com/1/trends/current.json?exclude=hashtags'; $ch = curl_init(); curl_setopt($ch, curlopt_url,$init); curl_setopt($ch, curlopt_returntransfer,1); $result = curl_exec($ch); curl_close($ch); $obj = json_decode($result, true);   foreach ($obj[0]['trends'] $trend) {     print $trend['query'];     echo "<br>";     print $trend['name'];     echo "<hr>"; }  ?> 

and getting error:

notice: undefined offset: 0 in \index.php on line 11

warning: invalid argument supplied foreach() \index.php on line 11

you read json wrong. need following:

foreach ($obj['trends']['2011-02-23 18:00:00'] $trend) {     print $trend['query'];     echo "<br>";     print $trend['name'];     echo "<hr>"; } 

Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -