Preventing double encode of URL in PHP

PHP

Read {count} times since 2020

There is no practical way to check whether an URL is encoded or not to encode if it’s not encoded. But you can do encode the URL by first decoding like below:

$string = url_decode($url);

And then you should encode as to prevent double encoding.

$string = url_encode($url);

By doing this we can prevent double encoding of URL‘s.