PHP字符串特殊字符


PHP string specialchars

我正在通过Android上的应用程序设置一个可用的小web服务。服务器端的功能如下:

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

问题是,如果我用$url查询谷歌(如上面的例子),它返回JSON与'INVALID REQUEST',但如果在第一个curl_opt的查询是用$curlW完成的,将像一个魅力。
在调试时,我发现,使$url返回,这使得每个&转换( curl_init之前!)在&amp…!所以我尝试了几乎所有PHP字符串函数来强制每个&解码或替换每个实体&而不产生任何结果。
任何建议吗?

你做错了什么

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