首页 > 文章列表 > 如何通过PHP获取网页内容

如何通过PHP获取网页内容

php 精选
407 2024-03-07

PHP中,可以使用file_get_contents()函数来获取网页内容。可以通过传入网页的URL作为参数来获取该网页的内容。

示例代码如下:

$url = "Http://example.com"; // 网页的URL
$content = file_get_contents($url); // 获取网页内容

echo $content; // 输出网页内容

请注意,file_get_contents()函数在打开URL时需要启用allow_url_fopen选项。如果该选项被禁用,该函数将无法工作。