URL Decoding in PHP

Brandon Jackson picture Brandon Jackson · Nov 18, 2009 · Viewed 88k times · Source

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?

Answer

Kristoffer Bohmann picture Kristoffer Bohmann · Nov 18, 2009

Your string is also UTF-8 encoded. This will work:

echo utf8_decode(urldecode("Ant%C3%B4nio+Carlos+Jobim"));

Output: "Antônio Carlos Jobim".