PHP access to remote file content function _php tips

Source: Internet
Author: User
Tags learn php learn php programming php programming

A simple PHP access to the remote file content of the function code, strong compatibility. Direct calls make it easy to get the contents of a remote file, and you can use this function to get pictures. The code is as follows:

/**

 * Read remote content

 * @return String */
function get_url_content ($url) {

  if (function_exists) ("Curl_init" ) {

    $ch = Curl_init ();

    $timeout =;

    curl_setopt ($ch, Curlopt_url, $url);

    curl_setopt ($ch, Curlopt_returntransfer, 1);

    curl_setopt ($ch, Curlopt_connecttimeout, $timeout);

    $file _contents = curl_exec ($ch);

    Curl_close ($ch);

  else{

    $is _auf=ini_get (' Allow_url_fopen ')? True:false;

    if ($is _auf) {

      $file _contents = file_get_contents ($url);

    }

  }

  return $file _contents;

}

The above is the PHP to get the content of the remote file function code, I hope this article for everyone to learn PHP programming help.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.