file_get_contents 请求的 URL 地址中的&符号被转译成"&"怎么才能让它不转译

2017-10-16 12:11:49 +08:00
 solaro

ErrorException: file_get_contents( http://apis.map.qq.com/ws/geocoder/v1/?location=30.879607817556,104.24672753578&get_poi=1&key=O2RBZ-HY5WU): failed to open stream: Connection timed out in /data/www/xxxx.com/cc.xxxx.com/app/Http/Controllers/BaseController.php:1754 Stack trace:

一直报错,发现问题是&get_poi=1& 中的&符号被转译掉了,qq 地图不认

3049 次点击
所在节点    PHP
7 条回复
crab
2017-10-16 12:16:05 +08:00
用 %26 试下
f2f2f
2017-10-16 12:16:40 +08:00
('') 单引号
VgV
2017-10-16 12:18:05 +08:00
你是怎么传递给 file_get_contents 里面的? get ?那建议先把&换成其他字符串,传进去的的时候再替换回来。post 一般没事
silenceeeee
2017-10-16 12:19:15 +08:00
```

$url = 'http://apis.map.qq.com/ws/geocoder/v1/?location=30.879607817556,104.24672753578&get_poi=1&key=O2RBZ-HY5WU';

$ret = file_get_contents($url);

var_dump($ret);

```

没啥问题啊。
klgd
2017-10-16 12:20:37 +08:00
file_get_contents 不会去转义 url 吧,是不是你获取到的 url 已经被转义了,用 htmlspecialchars_decode 反转义一下试试
vus520
2017-10-16 16:05:03 +08:00
`curl xxxxx.ooo`

难道只有我懂这个技能么
yzmm
2017-10-16 17:46:25 +08:00
@vus520 执行命令会遇到禁用命令执行

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/397978

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX