我用file_get_contents($url);这个方法不行
`$url = $_POST['url'];
$ch = curl_init();
$timeout = 3;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$contents = curl_exec($ch);
curl_close($ch);
echo $contents;
exit;`
url是在前端输入的,我试过了,输入www.baidu.com,显示的仍是百度的界面,而不是他的html源代码
数据分析师2017-10-01 00:53:33
How does php get the html source code of its corresponding page from a URL?-PHP Chinese website Q&A-How does php get the html source code of its corresponding page from a URL?-PHP Chinese website Q&A
Take a look around and learn.
阿神2017-03-17 14:25:31
<?php $pagecontent = file_get_contents("http://www.php.cn"); echo htmlspecialchars($pagecontent);//htmlentities 或者htmlspecialchars ?>
这样就好了吧 你试试