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

php – 等效于file_get_contents()与CURL?

发布时间:2020-12-13 16:25:52 所属栏目:PHP教程 来源:网络整理
导读:我正在尝试从这个URL获取一些 JSON数据: $url = 'http://site.com/search.php?term=search term here';$result = json_decode ( file_get_contents($url) ); 但是,客户端的webhost已禁用allow_url_fopen设置,因此上述代码不起作用. 上面的行的等效代码是什
我正在尝试从这个URL获取一些 JSON数据:
$url = 'http://site.com/search.php?term=search term here';
$result = json_decode ( file_get_contents($url) );

但是,客户端的webhost已禁用allow_url_fopen设置,因此上述代码不起作用.

上面的行的等效代码是什么?基本上,搜索字词需要通过$_GET提交到网址.

喜欢这个:
$url = 'http://site.com/search.php?term=search term here';

$rCURL = curl_init();

curl_setopt($rCURL,CURLOPT_URL,$url);
curl_setopt($rCURL,CURLOPT_HEADER,0);
curl_setopt($rCURL,CURLOPT_RETURNTRANSFER,1);

$aData = curl_exec($rCURL);

curl_close($rCURL);

$result = json_decode ( $aData );

(编辑:李大同)

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

    推荐文章
      热点阅读