Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a html text. I had encoded it in php using urlencode function. I want to decode that text in the javascript. when i use unescape function in javascript it replaces all the special characters back but sapce is replaced by '+'. how can i do it correctly so that space is replaced as space itself???

share|improve this question
add comment (requires an account with 50 reputation)

3 Answers

up vote 6 down vote accepted

Try using rawurlencode instead - urlencode does some things differently for "historical" reasons.

See http://us.php.net/manual/en/function.urlencode.php for more information.

share|improve this answer
tht works for me – Jasim Jul 9 '09 at 18:19
add comment (requires an account with 50 reputation)
PHP rawUrlEncode() == JavaScript encodeURIComponent()

and vice versa

PHP rawUrlDecode() == JavaScript decodeURIComponent()
share|improve this answer
add comment (requires an account with 50 reputation)

Try this:

return decodeURIComponent((str + '').replace(/\+/g, '%20'));

Source: http://phpjs.org/functions/urldecode:572

share|improve this answer
add comment (requires an account with 50 reputation)

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.