获取网页HTML代码的PHP代码


PHP code to get the HTML code of a webpage

可能重复:
如何用PHP获取网页的HTML代码?

有没有PHP代码可以获取网页的HTML代码?$html=file_get_contents('https://stackoverflow.com/questions/ask');这行不通。它只是加载网页。我想在运行代码时显示HTML代码。

提前谢谢。

尝试:

echo htmlentities(file_get_contents('http://stackoverflow.com/questions/ask'));

只对输出进行HTML编码,这样&变成&,使用htmlentities函数。

也许可以试试:

$html = htmlspecialchars(file_get_contents('http://stackoverflow.com/questions/ask'));

并尝试使用标签来输出。

$handle = @fopen("'http://www.webmasterworld.com", "rt");
$code = fread($handle,9000);

这是从另一个线程复制的,但应该足够好。它将获得$handle中的代码,然后$code将包含该代码的9000字节。

尝试将exec和wget一起使用:

<?php
exec('wget http://stackoverflow.com/questions/ask -O', $array);
echo implode('<br />', $array);
?>