本文介绍了相当于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 $_GET
to 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!