PHP collection remote server content code

Source: Internet
Author: User
Keywords Web Programming PHP Tutorials
Tags access code content echo function link php programming

PHP collection remote server content code

Method simulates a user's access to a Web page

function Readpr ($link, $url)
{
$fp = Fsockopen ($url, $errno, $errstr, 30);
if (! $fp)
{
echo "$errstr ($errno) n";
Exit (1);
}
Else
{
$out = "Get $link http/1.0rn";
$out. = "Host: $URLRN";
$out. = "user-agent:mozilla/4.0 (compatible; Googletoolbar 2.0.114.9-big; Linux 2.6) RN;
$out. = "Connection:closernrn";
Fwrite ($fp, $out);
do{
$line = fgets ($fp, 128);
}while ($line!== "RN");
$data = Fread ($fp, 8192);
Fclose ($FP);
return $data;
}
}//method Two uses Curl_init to read the Remote Web page content

function init ()
{
$ch = Curl_init ();
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);
}
Method Three simplest use file_get_contents

function GetFiles ($value)
{
$get _file = @file_get_contents ($value);
}
Method four uses the fopen to collect the remote webpage content

function GetFiles ($value)
{
Return fopen ($value);
}


Related Article

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.