一、用file_get_contents函數(shù),以post方式獲取url
目前創(chuàng)新互聯(lián)公司已為上千余家的企業(yè)提供了網(wǎng)站建設(shè)、域名、虛擬主機、網(wǎng)站托管、服務(wù)器租用、企業(yè)網(wǎng)站設(shè)計、鶴山網(wǎng)站維護等服務(wù),公司將堅持客戶導向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。
?php
$url=?'';
$data=?array('foo'=?'bar');
$data= http_build_query($data);
$opts=?array(
'http'=?array(
'method'=?'POST',
'header'="Content-type: application/x-www-form-urlencoded\r\n" ?.
"Content-Length: " ?.?strlen($data) .?"\r\n",
'content'=?$data
)
);
$ctx= stream_context_create($opts);
$html= @file_get_contents($url,'',$ctx);
二、用file_get_contents以get方式獲取內(nèi)容
?php
$url='';
$html=?file_get_contents($url);
echo$html;
?
三、用fopen打開url, 以get方式獲取內(nèi)容
?php
$fp=?fopen($url,'r');
$header= stream_get_meta_data($fp);//獲取報頭信息
while(!feof($fp)) {
$result.=?fgets($fp, 1024);
}
echo"url header: {$header} br":
echo"url body: $result";
fclose($fp);
?
四、用fopen打開url, 以post方式獲取內(nèi)容
?php
$data=?array('foo2'=?'bar2','foo3'='bar3');
$data= http_build_query($data);
$opts=?array(
'http'=?array(
'method'=?'POST',
'header'="Content-type: application/x-www-form-
urlencoded\r\nCookie:cook1=c3;cook2=c4\r\n" ?.
"Content-Length: " ?.?strlen($data) .?"\r\n",
'content'=?$data
)
);
$context= stream_context_create($opts);
$html=?fopen(';id2=i4','rb',false,?$context);
$w=fread($html,1024);
echo$w;
?
五、使用curl庫,使用curl庫之前,可能需要查看一下php.ini是否已經(jīng)打開了curl擴展
?php
$ch= curl_init();
$timeout= 5;
curl_setopt ($ch, CURLOPT_URL,?'');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT,?$timeout);
$file_contents= curl_exec($ch);
curl_close($ch);
echo$file_contents;
?
a.php
?php
/*不知道你是想跳轉(zhuǎn)還是取回網(wǎng)頁內(nèi)容后顯示
$type為TRUE時采用頁面跳轉(zhuǎn)方式
$type為FALSE時采用取回內(nèi)容后顯示
*/
$type = TRUE;
if( isset( $_GET['url'] ) ){
$url = 'http://' . $_GET['url'];
if( $type ){
header("Location: $url");
}else{
$page = file_get_contents($url);
echo $page;
}
}else{
echo '未設(shè)置URL參數(shù)';
}
?
如果你要
和
之間的所有源碼,用 preg_match 就可以,不用preg_match_all ,如果你要里面的所有的
標簽中的內(nèi)容,可以用preg_match_all //提取所有代碼 $pattern = '/
(.+?)
/is'; preg_match($pattern, $string, $match); //$match[0] 即為
和
之間的所有源碼 echo $match[0]; //然后再提取
之間的內(nèi)容 $pattern = '/(.+?)li/is'; preg_match_all($pattern, $match[0], $results); $new_arr=array_unique($results[0]); foreach($new_arr as $kkk){ echo $kkk; }
網(wǎng)頁題目:php調(diào)用網(wǎng)頁數(shù)據(jù) php調(diào)用html
本文鏈接:http://chinadenli.net/article30/dogdhso.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制開發(fā)、網(wǎng)站改版、網(wǎng)站設(shè)計、電子商務(wù)、云服務(wù)器、App開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)