Tag Archives: RFC 3986

Javascript – Encode and decode URL like %20

When you want to create an url which contains special charaters like the whitespace, you need to convert it to %20 ascii value. In Javascript, you could simply make use of the built-in encodeURI() and decodeURI() as follow.

console.log(encodeURI("http://localhost:8000/?greeting=" + "Welcome to Eureka!"));
// Output

// Output
// http://localhost:8000/?greeting=Welcome to Eureka!


You can do it in PHP as well.
PHP – URL Encode and Decode

Done =)