PHP抓取页面代码四种 方法: 1. file()函数 2. file_get_contents()函数 3. fopen()->fread()->fclose()模式 4.curl方式 file()方法: <?php $url='http://t.qq.com'; $lines_array=file($url); $lines_string=implode('',$lines_array); echo htmlspecialchars($lines_string); ?> file_get_contents()方法: <?php $url='http://t.qq.com'; $lines_string=file_get_contents($url); echo htmlspecialchars($lines_string); ?> fopen()->fread()->fclose()模式 <?php $url='http://t.qq.com'; $handle=fopen($url,"rb"); $lines_string=""; do{ $data=fread($handle,1024); if(strlen($data)==0){break;} $lines_string.=$data; }while(true); fclose($handle); echo htmlspecialchars($lines_string); ?> CURL方法: <?php $url='http://t.qq.com'; $ch=curl_init(); $timeout=5; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $lines_string=curl_exec($ch); curl_close($ch); echo htmlspecialchars($lines_string); ?>