本文介绍了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);
  ?>

dawei

【声明】:达州站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。