mavera2 Posted September 23, 2011 Share Posted September 23, 2011 By using twitter api, i'm trying to get latest trends. I need to take trends name and creation time of the list. Can you help me to obtain the values from the array? Thank you This code doesn't work. <?php $jsonurl = 'http://api.twitter.com/1/trends/44418.json'; $json = file_get_contents($jsonurl,0,null,null); $json_output = json_decode($json); foreach ( $json_output->trends as $trend ) { echo "{$trend->name}\n"; } ?> Quote Link to comment Share on other sites More sharing options...
WebStyles Posted September 23, 2011 Share Posted September 23, 2011 try this: <?php $jsonurl = 'http://api.twitter.com/1/trends/44418.json'; $json = file_get_contents($jsonurl,0,null,null); $json_output = json_decode($json,true); $trends = $json_output[0]['trends']; foreach ( $trends as $trend ){ echo $trend['name']."<br />"; } ?> *whenever you're in doubt with arrays, it's best to use: echo '<pre>'; print_r($array); to look at the whole structure of the returned/converted array. EDIT: Sorry, forgot the creation date/time, it will be in: echo $json_output[0]['as_of']; Quote Link to comment Share on other sites More sharing options...
mavera2 Posted September 23, 2011 Author Share Posted September 23, 2011 try this: <?php $jsonurl = 'http://api.twitter.com/1/trends/44418.json'; $json = file_get_contents($jsonurl,0,null,null); $json_output = json_decode($json,true); $trends = $json_output[0]['trends']; foreach ( $trends as $trend ){ echo $trend['name']."<br />"; } ?> *whenever you're in doubt with arrays, it's best to use: echo '<pre>'; print_r($array); to look at the whole structure of the returned/converted array. EDIT: Sorry, forgot the creation date/time, it will be in: echo $json_output[0]['as_of']; That really helped me much ) Thank you for your help and suggestions. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.