1.fopen体式格局
//接见指定URL函数 function access_url($url) { if ($url=='') return false; $fp = fopen($url, 'r') or exit('Open url faild!'); if($fp){ while(!feof($fp)) { $file.=fgets($fp).""; } fclose($fp); } return $file; }
引荐进修:PHP视频教程
2.file_get_contents体式格局(翻开长途文件的时刻会形成CPU飙升。file_get_contents实在也能够post)
$content = file_get_contents("http://www.google.com");
3.curl体式格局
function curl_file_get_contents($durl){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $durl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true) ; // 猎取数据返回 curl_setopt($ch, CURLOPT_BINARYTRANSFER, true) ; // 在启用 CURLOPT_RETURNTRANSFER 时刻将猎取数据返回 $r = curl_exec($ch); curl_close($ch); return $r; }
4.fsockopen体式格局(只能猎取网站主页信息,其他页面不能够)
$fp = fsockopen("www.example.com", 80, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)<br />\n"; } else { $out="GET / HTTP/1.1\r\n"; $out.="Host: www.example.com\r\n"; $out.="Connection: Close\r\n\r\n"; fwrite($fp, $out); while (!feof($fp)) { echo fgets($fp, 128); } fclose($fp); }
以上就是php接见url的四种体式格局的细致内容,更多请关注ki4网别的相干文章!