相当于file_get_contents()与CURL? [英] Equivalent of file_get_contents() with CURL?

查看:169
本文介绍了相当于file_get_contents()与CURL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从这样的网址获取一些JSON数据:

I'm trying to get some JSON data from a url like this:

$url = 'http://site.com/search.php?term=search term here';
$result = json_decode ( file_get_contents($url) );

设置已停用,因此上述代码不起作用。

However the client's webhost has got the allow_url_fopen setting disabled, hence the code above doesn't work.

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

What's the equivalent code of the lines above? Basically, a search term needs to be submitted via $_GETto the url.

推荐答案

像这样:

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

这篇关于相当于file_get_contents()与CURL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆