Get data from a URL using cURL PHP


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



Copy this code and paste it in your HTML
  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. return $data;
  16. }
  17. ?>

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.