curl - fetch twitter trends


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2. $url = 'http://search.twitter.com/trends.json';
  3. $ch = curl_init();
  4. curl_setopt($ch, CURLOPT_URL, $url);
  5. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  6. $output = curl_exec($ch);
  7. curl_close($ch);
  8. $data = json_decode($output);
  9. #print_r($data);
  10. echo '<h2>Twitter trending topics ('.$data->as_of.')</h2>';
  11. echo '<ul>';
  12. foreach ($data->trends as $t){
  13. echo '<li><a href="'.$t->url.'">'.$t->name.'</a></li>';
  14. }
  15. echo '</ul>';
  16. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.