V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
solaro
V2EX  ›  PHP

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

  •  
  •   solaro · 2017-10-16 12:11:49 +08:00 · 3033 次点击
    这是一个创建于 2356 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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 地图不认

    7 条回复    2017-10-16 17:46:25 +08:00
    crab
        1
    crab  
       2017-10-16 12:16:05 +08:00
    用 %26 试下
    f2f2f
        2
    f2f2f  
       2017-10-16 12:16:40 +08:00
    ('') 单引号
    VgV
        3
    VgV  
       2017-10-16 12:18:05 +08:00
    你是怎么传递给 file_get_contents 里面的? get ?那建议先把&换成其他字符串,传进去的的时候再替换回来。post 一般没事
    silenceeeee
        4
    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
        5
    klgd  
       2017-10-16 12:20:37 +08:00
    file_get_contents 不会去转义 url 吧,是不是你获取到的 url 已经被转义了,用 htmlspecialchars_decode 反转义一下试试
    vus520
        6
    vus520  
       2017-10-16 16:05:03 +08:00
    `curl xxxxx.ooo`

    难道只有我懂这个技能么
    yzmm
        7
    yzmm  
       2017-10-16 17:46:25 +08:00
    @vus520 执行命令会遇到禁用命令执行
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5368 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 08:35 · PVG 16:35 · LAX 01:35 · JFK 04:35
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.