solaro
V2EX  ›  PHP

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

  •  
  •   solaro · Oct 16, 2017 · 3999 views
    This topic created in 3304 days ago, the information mentioned may be changed or developed.

    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 replies  •  2017-10-16 17:46:25 +08:00
    crab
    crab
    Oct 16, 2017
    1
    用 %26 试下
    f2f2f
    f2f2f
    Oct 16, 2017
    2
    ('') 单引号
    VgV
    VgV
    Oct 16, 2017
    3
    你是怎么传递给 file_get_contents 里面的? get ?那建议先把&换成其他字符串,传进去的的时候再替换回来。post 一般没事
    silenceeeee
    silenceeeee
    Oct 16, 2017
    4
    ```

    $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
    klgd
    Oct 16, 2017
    5
    file_get_contents 不会去转义 url 吧,是不是你获取到的 url 已经被转义了,用 htmlspecialchars_decode 反转义一下试试
    vus520
    vus520
    Oct 16, 2017
    6
    `curl xxxxx.ooo`

    难道只有我懂这个技能么
    yzmm
    yzmm
    Oct 16, 2017
    7
    @vus520 执行命令会遇到禁用命令执行
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   5368 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 01:52 · PVG 09:52 · LAX 17:52 · JFK 20:52
    ♥ Do have faith in what you're doing.