PHP中的URL解码

Bra*_*son 32 php url utf-8 urldecode

我正在尝试使用PHP的urldecode函数解码此URL字符串:

urldecode("Ant%C3%B4nio+Carlos+Jobim");
Run Code Online (Sandbox Code Playgroud)

这应该输出......

'Antônio Carlos Jobim'
Run Code Online (Sandbox Code Playgroud)

......但反过来就是这个

'Antônio Carlos Jobim'
Run Code Online (Sandbox Code Playgroud)

我已经在一个基于JS的在线解码器中测试了这个字符串并取得了巨大的成功,但似乎无法在服务器端进行操作.有任何想法吗?

Kri*_*ann 64

您的字符串也是 UTF-8编码的.这将有效:

echo utf8_decode(urldecode("Ant%C3%B4nio+Carlos+Jobim"));
Run Code Online (Sandbox Code Playgroud)

输出:"AntônioCarlosJobim".

  • 只有页面声明`ISO-8859-1`编码. (5认同)

Ign*_*s R 13

实际上,您获得了所需的输出,但它不被解释为UTF-8.如果这是在HTTP应用程序上,您应该发送标头或元标记(或两者),这将告诉客户端使用UTF-8.

编辑:例如:

// replace text/html with the content type you're using
header('Content-Type: text/html; charset=UTF-8');
Run Code Online (Sandbox Code Playgroud)