Linux 拨号vps windows公众号手机端

PHP怎么获取外部网页内容

lewis 6年前 (2020-01-21) 阅读数 10 #程序编程
文章标签 PHP

在PHP中获取外部网页内容通常使用cURL库或者file_get_contents()函数。下面分别介绍这两种方法。

  1. 使用cURL库:
$url = 'http://www.example.com';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);

echo $output;
  1. 使用file_get_contents()函数:
$url = 'http://www.example.com';
$output = file_get_contents($url);

echo $output;

这两种方法都可以用来获取外部网页的内容,但是cURL库比file_get_contents()函数更强大和灵活,可以设置更多的选项和参数。

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门