简体   繁体   English

通过PHP检索网页内容的最简单方法是什么?

[英]What's the easiest way to retrieve the contents of a webpage via PHP?

I want to write a function to retrieve the contents of a webpage so it works like: 我想编写一个函数来检索网页的内容,因此它的工作方式如下:

$url = "example.com";
$pageContent = RetrievePageContent($url);

What would be the easiest way to do this? 最简单的方法是什么?

Thanks in advance for your help! 在此先感谢您的帮助!

$pageContent = file_get_contents($url);

来自: file_get_contents

The easiest way is file_get_contents , which does exactly what you want: 最简单的方法是file_get_contents ,它正是您想要的:

$url = "http://example.com";
$pageContent = file_get_contents($url);

You can use the fopen command and pass it a URL. 您可以使用fopen命令并将其传递给URL。 However, this ability might be disabled by your host. 但是,此功能可能已被您的主机禁用。 The best practice would be to use the cURL functions . 最佳实践是使用cURL函数 The documentation includes sample code that does exactly what you're trying to do. 文档包括示例代码 ,这些代码完全可以完成您要执行的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM