最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

PHP讀取網(wǎng)頁文件內(nèi)容的實現(xiàn)代碼(fopen,curl等)

 更新時間:2011年06月23日 13:22:12   作者:  
php小偷程序中經(jīng)常需要獲取遠程網(wǎng)頁的內(nèi)容,下面是一些實現(xiàn)代碼,需要的朋友可以慘況下。
1.fopen實現(xiàn)代碼:
復(fù)制代碼 代碼如下:

<?php
$handle = fopen ("http://www.example.com/", "rb");
$contents = "";
while (!feof($handle)) {
$contents .= fread($handle, 8192);
}
fclose($handle);
?>

復(fù)制代碼 代碼如下:

<?php
// 對 PHP 5 及更高版本
$handle = fopen("http://www.example.com/", "rb");
$contents = stream_get_contents($handle);
fclose($handle);
?>

2.curl實現(xiàn)代碼:
復(fù)制代碼 代碼如下:

<?php
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";
$contents=_url($pageURL);
?>

編碼轉(zhuǎn)換函數(shù)
復(fù)制代碼 代碼如下:

$html = file_get_contents("http://s.jb51.net");
$html = iconv( "Big5", "UTF-8//IGNORE" , $html); //轉(zhuǎn)化編碼方式為UTF8
print $html;
$htm = file("http://s.jb51.net");
$h = "";
foreach($htm as $value)
{
$h.= iconv( "GB2312", "utf-8//IGNORE" , $value);
}
print_r($h);

另一種打開網(wǎng)頁的方法
復(fù)制代碼 代碼如下:

<?php
$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);
?>

相關(guān)文章

最新評論

澄城县| 弥渡县| 大洼县| 邵东县| 石门县| 巴林右旗| 雷波县| 通化县| 萨嘎县| 宜黄县| 阿城市| 大姚县| 辽阳县| 利津县| 特克斯县| 广南县| 民丰县| 庆阳市| 河西区| 成安县| 南平市| 肥城市| 高淳县| 安庆市| 怀集县| 嘉鱼县| 独山县| 海晏县| 贺州市| 六安市| 西宁市| 凤阳县| 察哈| 枝江市| 萝北县| 长海县| 孝感市| 刚察县| 哈尔滨市| 龙里县| 绥棱县|