Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

URL Decoding in PHP

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?

like image 407
Brandon Jackson Avatar asked Nov 18 '09 15:11

Brandon Jackson


People also ask

Does PHP automatically decode URL?

Yes, all the parameters you access via $_GET and $_POST are decoded.

How encode URL in PHP?

PHP | urlencode() Function. The urlencode() function is an inbuilt function in PHP which is used to encode the url. This function returns a string which consist all non-alphanumeric characters except -_. and replace by the percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs.

What does URL decode do?

URL encoding converts characters that are not allowed in a URL into character-entity equivalents; URL decoding reverses the encoding. For example, when embedded in a block of text to be transmitted in a URL the characters < and > are encoded as %3c and %3e.

What is Urlencode and Urldecode in PHP?

application/x-www-form-urlencoded type This is a type of encoding-decoding approach where the built-in PHP functions urlencode() and urldecode()are implemented to encode and decode the URL, respectively. This encoding will replace almost all the special characters other than (_), (-), and (.) in the given URL.


1 Answers

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

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

Output: "Antônio Carlos Jobim".

like image 143
Kristoffer Bohmann Avatar answered Sep 22 '22 10:09

Kristoffer Bohmann