URL Reader

This function will download the contents of any URL and return it as a string that you can save to a file or database. It will use curl if it is installed. Otherwise it will use fopen/fread.
<?php
function url_reader($url,$referer=null) {
  if (function_exists('curl_init')) {
    $ch  =  curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    if ($referer) {
      curl_setopt($ch, CURLOPT_REFERER, $referer);
    }
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $data = curl_exec($ch);
    curl_close($ch);
  }
  else {
    $data = '';
    $handle = fopen($url,'rb');
    while (!feof($handle)) {
      $data .= fread($handle, 8192);
    }
    fclose($handle);
  }
  return $data;
}
?>

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

good

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <b> <i> <strong> <cite> <em> <code> <pre> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <css>, <diff>, <drupal5>, <html>, <javascript>, <php>. The supported tag styles are: <foo>, [foo]. PHP source code can also be enclosed in <?php ... ?> or <% ... %>.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.