通过file_get_html获取网页的来源

时间:2012-05-05 09:32:36

标签: php

我使用file_get_html来简单的html DOM,但我无法弄清楚如何获取网址的页面来源! 有什么办法吗?我不是在谈论paintext!

由于

1 个答案:

答案 0 :(得分:4)

尝试file_get_contents。它将获取网站URL的来源

如果你想看到源代码,试试这个

echo htmlentities(file_get_contents("http://www.google.com"));

http://php.net/manual/en/function.file-get-contents.php

您也可以使用CURL

来完成此操作
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $file);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, "http://www.google.com");
$result = curl_exec($ch);
curl_close($ch);
相关问题