加入收藏 | 设为首页 | 会员中心 | 我要投稿 宁德站长网 (https://www.0593zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php怎么调用远程数据

发布时间:2024-01-03 09:23:09 所属栏目:PHP教程 来源:DaWei
导读: 本文介绍了php调用远程数据的方法,php curl调用远程数据的例子,需要的朋友参考下。

默认不打开文件系统和流配置选项 allow_url_fopen ,建议使用一个替代的函数模块 cURL。

php cUR
本文介绍了php调用远程数据的方法,php curl调用远程数据的例子,需要的朋友参考下。

默认不打开文件系统和流配置选项 allow_url_fopen ,建议使用一个替代的函数模块 cURL。

php cURL 远程读取数据的方法:

allow_url_fopen = On:
 
代码示例:
$str = file_get_contents("https://www.mycodes.net");
if ($str !== false) {
// do something with the content
echo $str;
}
?>

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);
?>

(编辑:宁德站长网)

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

    推荐文章