Search code examples
phpvb.neturlwebaffiliate

Percent-encode URL Twice


I have been given some instructions to percent encode a URL twice. I know how to percent encode a URL once but how do you do it twice?

Surly when it is encoded once, it will be the same when encoded again.

Have I missed something?

Instructions or algorithm would be great!


Solution

  • It won't be the same since you encode the % used for encoding.

    $url = 'http://www.youtube.com/watch?v=35_0IN36rUI'
    echo $url;
    echo urlencode($url);
    echo urlencode(urlencode($url));
    

    will give:

    http://www.youtube.com/watch?v=35_0IN36rUI
    http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D35_0IN36rUI
    http%253A%252F%252Fwww.youtube.com%252Fwatch%253Fv%253D35_0IN36rUI