登陆

php如何从一个网址中获取到他所对应页面的html源代码?

我用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源代码

# PHP
phpcn_u238phpcn_u2381685 天前504 次浏览

全部回复(2)我要回复

  • 数据分析师

    数据分析师2017-10-01 00:53:33

    php如何从一个网址中获取到他所对应页面的html源代码?-PHP中文网问答-php如何从一个网址中获取到他所对应页面的html源代码?-PHP中文网问答

    围观一下哦,学习一下。

    回复
    0
  • 阿神

    阿神2017-03-17 14:25:31

    <?php
     $pagecontent = file_get_contents("//m.sbmmt.com"); 
     echo htmlspecialchars($pagecontent);//htmlentities 或者htmlspecialchars
     ?>

    这样就好了吧  你试试

    回复
    0
  • 取消回复发送