php怎么调用远程数据?完成代码
发布时间:2022-01-16 14:51:31 所属栏目:PHP教程 来源:互联网
导读:本文介绍了php调用远程数据的方法,php curl调用远程数据的例子,需要的朋友参考下。 默认不打开文件系统和流配置选项 allow_url_fopen ,建议使用一个替代的函数模块 cURL。 php cURL 远程读取数据的方法: 例1,allow_url_fopen = On: 代码示例: $str = f
本文介绍了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); ?> (编辑:晋中站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |