1.fopen Implementation code:
Copy the Code code as follows:
$handle = fopen ("http://www.example.com/", "RB");
$contents = "";
while (!feof ($handle)) {
$contents. = Fread ($handle, 8192);
}
Fclose ($handle);
?>
Copy the Code code as follows:
For PHP 5 and later
$handle = fopen ("http://www.example.com/", "RB");
$contents = Stream_get_contents ($handle);
Fclose ($handle);
?>
2.curl Implementation code:
Copy the Code code as follows:
function _url ($Date) {
$ch = Curl_init ();
$timeout = 5;
curl_setopt ($ch, Curlopt_url, "$Date");
curl_setopt ($ch, Curlopt_returntransfer, 1);
curl_setopt ($ch, Curlopt_useragent, "mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ");
curl_setopt ($ch, Curlopt_connecttimeout, $timeout);
$contents = curl_exec ($ch);
Curl_close ($ch);
return $contents;
}
$pageURL = "http://www.baidu.com";
$c
?>
Encoding Conversion functions
Copy the Code code as follows:
$html = file_get_contents ("http://s.jb51.net");
$html = Iconv ("Big5", "Utf-8//ignore", $html); Conversion encoding mode is UTF8
Print $html;
$htm = File ("Http://s.jb51.net");
$h = "";
foreach ($htm as $value)
{
$h. = Iconv ("GB2312", "Utf-8//ignore", $value);
}
Print_r ($h);
Another way to open a Web page
Copy the Code code as follows:
$opts = Array (
' HTTP ' =>array (
' Method ' = ' GET ',
' Header ' = ' accept-language:en\r\n '.
"Cookie:foo=bar\r\n"
)
);
$context = Stream_context_create ($opts);
/* Sends an HTTP request to www.example.com
With additional headers shown above */
$fp = fopen (' http://www.baidu.com ', ' R ', false, $context);
Fpassthru ($FP);
Fclose ($FP);
?>
The above describes the FOP PHP read page file content implementation code Fopen,curl, including the FOP aspects of the content, I hope that the PHP tutorial interested in a friend helpful.