Posted By

zack on 07/02/11


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

shanford


Get data from a URL using cURL PHP


 / Published in: PHP
 

URL: http://www.digimantra.com/technology/php/get-data-from-a-url-using-curl-php/

  1. <?php
  2. $url='http://twitter.com/statuses/user_timeline/16387631.json'; //rss link for the twitter timeline
  3. print_r(get_data($url)); //dumps the content, you can manipulate as you wish to
  4.  
  5. /* gets the data from a URL */
  6.  
  7. function get_data($url)
  8. {
  9. $ch = curl_init();
  10. $timeout = 5;
  11. curl_setopt($ch,CURLOPT_URL,$url);
  12. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  13. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
  14. $data = curl_exec($ch);
  15. curl_close($ch);
  16. return $data;
  17. }
  18. ?>

Report this snippet  

You need to login to post a comment.