0

I know the following works to share a link to FB:

https://www.facebook.com/sharer/sharer.php?u=http://rot47.net/picture-gallery/categories.php

But, this also works:

https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Frot47.net%2Fpicture-gallery%2Fcategories.php

If both works, why should we use urlencode in PHP??

justyy
  • 5,831
  • 4
  • 40
  • 73
  • *Some* of the query string needs to be encoded. Using urlencode is "safe" as it encodes everything that *could* have meaning, but it does not always lead to the prettiest results as illustrated. [I wrote this answer on it](http://stackoverflow.com/questions/24970406/how-to-pass-url-with-parameter-as-a-parameter/24970531#24970531). Note that `&` characters, for example, must still be encoded. – user2864740 Aug 10 '14 at 19:26
  • possible duplicate of [Why url encode, or which characters to encode](http://stackoverflow.com/questions/9086296/why-url-encode-or-which-characters-to-encode) – Scimonster Aug 10 '14 at 19:55

1 Answers1

0

As soon as you have a query string with multiple parts or a fragment id, it stops working (since the & or # would be processed as part of the facebook url and not the rot47 url).

Encoding the data by default is just good defensive programming.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335