douyin9987 2015-03-26 14:35
浏览 40

如何编码/解码国际URL以便在PHP中呈现

I'm struggling to find a solution (built in or library) to the problem of decoding a URL containing percent-encoded characters outside the ASCII range.

As far as I understand RFC 3986 we shouldn't decode a URL as a whole, without first breaking it into components. However, this seems to be what browsers do with "international" characters. For example if I paste this URL into the address bar of Google Chrome:

http://www.example.com/?x=7%26z%3D6&q=%C3%A9

It is rendered as this:

http://www.example.com/?x=7%26z%3D6&q

So how do I do this with PHP without implementing my own url decoder? The built-in functionality (i.e urldecode) would return:

http://www.example.com/?x=7&z=6&q

Which is wrong (because there are now 3 query parameters) but expected (because urldecode is not designed to be used on entire urls)

I would like to be able to replicate the browser behaviour when displaying links in my application: in the href attribute I'll use the percent encoded form but in the anchor itself I'll use the "pretty" form.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 mysql架构,按照姓名分表
    • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
    • ¥15 Macbookpro 连接热点正常上网,连接不了Wi-Fi。
    • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
    • ¥15 linux驱动,linux应用,多线程
    • ¥20 我要一个分身加定位两个功能的安卓app
    • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
    • ¥15 IAR程序莫名变量多重定义
    • ¥15 (标签-UDP|关键词-client)
    • ¥15 关于库卡officelite无法与虚拟机通讯的问题