Encode/Decode URL in Javascript and PHP

PHP

Read {count} times since 2020

URL encoding and decoding can be done in both Javascript and PHP. In this post I’m going to tell you the functions used in both languages for url encoding/decoding.
Javascript
 Encoding

encodeURIComponent(url);

Decoding

decodeURIComponent(url);

PHP
 Encoding

urlencode(url);

Decoding

urldecode(url);

There is an encodeURI and decodeURI function in Javascript but it won’t encode/decode the url. Note that the the word used in Javascript is URI not URL. But in PHP both are URL. Don’t mistake the word.

Show Comments