Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript equivalent to php's urldecode()

I wrote a custom xml parser and its locking up on special characters. So naturally I urlencoded them into my database.

I can't seem to find an equivalent to php's urldecode().

Are there any extentions for jquery or javascript that can accomplish this?

like image 954
Derek Adair Avatar asked Aug 07 '10 18:08

Derek Adair


People also ask

What is Urldecode?

The urldecode() function is an inbuilt function in PHP which is used to decode url which is encoded by encoded() function. Syntax: string urldecode( $input ) Parameters: This function accepts single parameter $input which holds the url to be decoded. Return Value: This function returns the decoded string on success.

What is Urlencode and Urldecode in PHP?

Another function called the urldecode() function is another inbuilt function of PHP and is implemented for decoding the URL, encoded by the urlencode() function. Decoding is the approach of reversing the non-ASCII data back to its original form. This function will accept a single string as its parameter.

What is decodeURIComponent?

The decodeURIComponent() function decodes a Uniform Resource Identifier (URI) component previously created by encodeURIComponent or by a similar routine.


1 Answers

You could use the decodeURIComponent function to convert the %xx into characters. However, to convert + into spaces you need to replace them in an extra step.

function urldecode(url) {   return decodeURIComponent(url.replace(/\+/g, ' ')); } 
like image 81
kennytm Avatar answered Sep 19 '22 22:09

kennytm