Digg 按钮拒绝编码的 url

发布于 2024-10-10 02:40:43 字数 702 浏览 2 评论 0原文

我写了一个 php 网站(它仍然是一个原型),并在上面放置了一个 Digg 按钮。这很简单,但是......

官方手册说:“URL 必须被编码”。我用 urlencode() 做到了这一点。 urlencode 之后,我的 URL 看起来像这样:

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

到目前为止,一切都很好,但是当我想将该 URL 提交到 Digg 时,它被识别为无效 URL:

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

如果我在“Airplane”和“crashed”之间放置一个“+”(位于链接末尾),然后 Digg 就可以毫无问题地识别它!

请帮忙,这个奇怪的问题正在杀死我的脑细胞!

PS 出于此答案的目的,网址已更改(更改为不存在的网址),因为在原始版本中涉及非英语网站。

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 nonexisting ones) because, in the original, non-english sites are involved.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

缱倦旧时光 2024-10-17 02:40:43

urlencode()编辑后,也对生成的加号进行编码:

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

或者,您可以先用 + 替换 URL 中的空格,然后用 urlencode() 结果:

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

如果您自己的站点首先需要对查询字符串中的参数进行编码,那么您就不会有问题(因为原始站点中不会有未编码的空间)网址)。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文