PHP analog user gets remote file content

Source: Internet
Author: User
Tags curl

1,ini_get:returns The value of the configuration option as a string on success, or a empty string on failure (read PHP teaching The value in the path. ini configuration file)
2,; Whether to allow the treatment of URL (like http://or ftp://) as files.
Allow_url_fopen = On (content in profile)
3,fopen ("RB"): If you do not specify ' B ' tags when manipulating binaries, you may encounter some strange problems, including bad picture files and strange questions about RN characters.
Note: For portability reasons, it is strongly recommended that you always use the ' B ' flag when you open a file with fopen ().
Note: Again, for porting considerations, it is strongly recommended that you rewrite the code that relies on the ' t ' pattern to use the correct line terminator and change it to ' B ' mode.
4,strtolower--Make a string lowercase
5,curl_init (): Curl_init--Initialize A Curl session (initialize a Curl conversation)


.
/**
Gets the remote file contents
@param $url File http address
*/
Function Fopen_url ($url)
{
If function_exists (' fi Le_get_contents ') {
$file _content = @file_get_contents ($url);
} elseif (Ini_get (' Allow_url_fopen ') && ($file = @fopen ($url, ' RB ')) {
$i = 0;
while (!feof ($file) && $i + + < 1000) {
$file _content. = Strtolower (Fread ($file, 4096));
}
Fclose ($file);
} elseif (function_exists (' Curl_init ')) {
$curl _handle = Curl_init ();
curl_setopt ($curl _handle, Curlopt_url, $url);
curl_setopt ($curl _handle, curlopt_connecttimeout,2);
curl_setopt ($curl _handle, curlopt_returntransfer,1);
curl_setopt ($curl _handle, curlopt_failonerror,1);
curl_setopt ($curl _handle, curlopt_useragent, ' Trackback Spam check ');//reference spam check
$file _content = curl_exec ($ Curl_handle);
Curl_close ($curl _handle);
} else {
$file _content = ';
}
return $file _content;
}

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.