Urlencode () from PHP to JavaScript?

I am looking for a similar urlencode() function from PHP only in JavaScript. JQuery library is allowed.

Basically, I need to encode a string and then redirect the user to another page only using JavaScript.

+7
source share
4 answers

There is no function that fully matches urlencode() , but there is one equivalent to rawurlencode() : encodeURIComponent() .

Usage: var encoded = encodeURIComponent(str);

Here you can find the link:

https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/encodeURIComponent

+16
source

Take a look at phpjs.org if you are looking for a JS function equivalent to PHP:

http://phpjs.org/functions/urlencodeโˆ—73

Here you can use encodeURIComponent() (with some changes).

+2
source
0
source

Try urlencode from http://locutus.io/php/url/urlencode/ . I tested it on several occasions when it worked, and it worked.

0
source

All Articles