开发者

Digg button rejects encoded url

开发者 https://www.devze.com 2023-02-01 19:49 出处:网络
I wrote a php site (it\'s still a prototype) and I placed a Digg button on it. It was easy but... The official manual says: \"the URL has to be encoded\". I did that with urlencode(). After urlencode

I wrote a php site (it's still a prototype) and I placed a Digg button on it. It was easy but...

The official manual says: "the URL has to be encoded". I did that with urlencode(). After urlencode, my URL looks like this:

http%3A%2F%2Fwww.mysite.com%2Fen%2Fredirect.php%3Fl%3Dhttp%3A%2F%2Fwww.othersite.rs%2FNews%2FWorld%2F227040%2FRusia-Airplane-crashed%26N%3DRusia%3A+Airplane+crashed

So far it's good, but when I want to submit that URL to Digg, it is recognized as an invalid URL:

http://www.mysite.com/en/redirect.php?l=http://www.othersite.rs/News/World/227040/Rusia-Airplane-crashed&N=Rusia:+Airplane crashed

If I place a "+" between "Airplane" and "crashed" (at the end of the link), then Digg recognizes it without any problems!

Please help, this bizarre problem is killing my brain cells!

P.S. For purpose of this answer, urls are changed (to non开发者_开发技巧existing ones) because, in the original, non-english sites are involved.


After you've urlencode()ed it, encode the resulting plus signs as well:

$encoded_url = urlencode($original_url);
$final_url = str_replace('+', '%2B', $encoded_url);

Or alternatively, you could replace spaces in your URL with + first, and then urlencode() the result:

$spaceless_url = str_replace(' ', '+', $original_url);
$final_url = urlencode($spaceless_url);

If your own site required the parameters in the query string to be encoded in the first place, you wouldn't have the issue (since there wouldn't be an unencoded space in the original URL).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号