PHP字符串特殊字符

lu路28号

我正在设置一些可通过Android上的应用程序使用的网络服务。服务器中的功能是这样的:

 $lat=43.0552592;
 $lng=12.4483577;
 $radius=2000;

    $url = "https://maps.googleapis.com/maps/api/place/textsearch/json?query=italian&location=".$lat.",".$lng."&radius=".$raidus."&types=restaurant&sensor=false&key=".$apiKey;

    $urlW = "https://maps.googleapis.com/maps/api/place/textsearch/json?query=italian&location=43.0552592,12.4483577&radius=2000&types=restaurant&sensor=false&key=XXXXxxxXXxxXXxxxxXXX";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url);
    // Set so curl_exec returns the result instead of outputting it.
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    // Get the response and close the channel.
    $response = curl_exec($ch);

return $response;

麻烦的是,如果我使用来查询Google $url(如上例所示),则会使用来返回JSON 'INVALID REQUEST',但是如果第一次执行查询时curl_opt$curlW它将像一个超级按钮一样工作。
这是在调试我发现,做$url回报,即得到每个&转换(之前curl_init!)在&amp...!因此,我尝试了几乎所有的PHP字符串函数来强制每个&解码或将每个&entities强制替换&,而没有任何结果。
有什么建议吗?

依维索

你做错了什么

$url = "https://maps.googleapis.com/maps/api/place/textsearch/json?query=italian&location=".$lat.",".$lng."&radius=".$raidus."&types=restaurant&sensor=false&key=".$apiKey

应该

$url = "https://maps.googleapis.com/maps/api/place/textsearch/json?query=italian&location=".$lat.",".$lng."&radius=".$radius."&types=restaurant&sensor=false&key=".$apiKey;

但我不认为这是问题所在,请尝试使用file_get_contents()而不是curl,因此$ response将如下所示:

$response = file_get_contents($url);

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章