1 <?php 2 3 $url = "http://www.baidu.com/s?wd=刘俊涛的博客"; 4 5 $header = array( 6 'User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36', 7 ); 8 $ch = curl_init(); 9 curl_setopt($ch, CURLOPT_URL, $url); 10 curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 11 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 12 // 执行 13 $content = curl_exec($ch); 14 if ($content == false) { 15 echo "error:" . curl_error($ch); 16 } 17 // 关闭 18 curl_close($ch); 19 20 //输出结果 21 echo ($content);