加入收藏 | 设为首页 | 会员中心 | 我要投稿 PHP编程网 - 黄冈站长网 (http://www.0713zz.com/)- 数据应用、建站、人体识别、智能机器人、语音技术!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php怎么调用远程数据?完成代码

发布时间:2022-01-17 06:04:56 所属栏目:PHP教程 来源:互联网
导读:本文介绍了php调用远程数据的方法,php curl调用远程数据的例子,需要的朋友参考下。 默认不打开文件系统和流配置选项 allow_url_fopen ,建议使用一个替代的函数模块 cURL。 php cURL 远程读取数据的方法: 例1,allow_url_fopen = On: 代码示例: $str =
  本文介绍了php调用远程数据的方法,php curl调用远程数据的例子,需要的朋友参考下。
  默认不打开文件系统和流配置选项 allow_url_fopen ,建议使用一个替代的函数模块 cURL。
  php cURL 远程读取数据的方法:
 
  例1,allow_url_fopen = On:
  
 
  代码示例:
  $str = file_get_contents("https://www.mycodes.net");
  if ($str !== false) {
  // do something with the content
  echo $str;
  }
  ?>
  例2,allow_url_fopen = Off:
  
 
  代码示例:
  $ch = curl_init("https://www.mycodes.net/");
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $str = curl_exec($ch);
  if ($str !== false) {
  // do something with the content
  echo $str;
  }
  curl_close($ch);
  ?>

(编辑:PHP编程网 - 黄冈站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读