PHP 中的 URL 解码
我正在尝试使用 PHP 的 urldecode 函数解码此 URL 字符串:
urldecode("Ant%C3%B4nio+Carlos+Jobim");
这应该输出...
'Antônio Carlos Jobim'
...但相反,
'Antônio Carlos Jobim'
我已经在 基于JS的在线解码器取得了巨大成功,但似乎无法在服务器端执行此操作。有什么想法吗?
I am trying to decode this URL string using PHP's urldecode function:
urldecode("Ant%C3%B4nio+Carlos+Jobim");
This is supposed to output...
'Antônio Carlos Jobim'
...but instead is ouptutting this
'Antônio Carlos Jobim'
I've tested the string in a JS-based online decoder with great success, but can't seem to do this operation server side. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您的字符串也是 UTF-8 编码的。这将起作用:
输出:“Antônio Carlos Jobim”。
Your string is also UTF-8 encoded. This will work:
Output: "Antônio Carlos Jobim".
实际上,您得到了所需的输出,但它没有被解释为 UTF-8。如果这是在 HTTP 应用程序上,您应该发送标头或元标记(或两者),告诉客户端使用 UTF-8。
编辑:例如:
Actually, you get the desired output, but it is not interpreted as UTF-8. If this is on an HTTP application, you should send a header or a meta tag (or both) which would tell the client to use UTF-8.
Edit: for example:
当我
在浏览器中正确显示时,就像
我已经使用 XAMPP 进行了测试
when I do
Its display correctly in my browser like
I have tested with XAMPP
另一种选择是:
输出变为:
http://mysite.com
another option is:
output becomes :
http://mysite.com
在将其回显到页面之前,您是否也在使用
htmlenteties
?当我刚刚测试您的代码时,仅使用urldecode("Ant%C3%B4nio+Carlos+Jobim");
部分就可以正常工作,但是当我通过htmlentities
运行它时我得到了和你一样的输出。这似乎是 UTF-8 字符以及 PHP 如何处理
htmlentities
函数的问题。Are you also using
htmlenteties
before echoing it to the page? When I just tested your code it worked fine with just theurldecode("Ant%C3%B4nio+Carlos+Jobim");
part, but when I ran it throughhtmlentities
I got the same output as you did.It seems to be a problem with the UTF-8 characters and how PHP handles the
htmlentities
function.