Quantcast
Channel: Eureka! » RFC 3986
Viewing all articles
Browse latest Browse all 2

Javascript – Encode and decode URL like %20

0
0

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
http://localhost:8000/?greeting=Welcome%20to%20Eureka!


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

 

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

Done =)

Reference:


Filed under: Javascript Tagged: Javascript, RFC 3986

Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images