【问题标题】:Facebook Share Button Wont Share SymbolsFacebook 分享按钮不会分享符号
【发布时间】:2014-10-13 09:42:43
【问题描述】:

我在此处尝试使用此代码来共享我所在的当前页面,但某些 url 已关闭,因此它共享了错误的页面。我发现符号“&”被剪掉了,所以我想知道是否有人知道如何绕过它。

代码:

<a target="_blank" href="http://www.facebook.com/sharer/sharer.php?u=http://www.ibidthai.com/auction.pl?category=$form{'category'}&item=$form{'item'}">Share</a>

$form{'category'} 和 $form{'item'} 在这种情况下是一个变量,它的 category="car" 和 item="[]1415689774"

【问题讨论】:

  • 您需要添加更多细节并发布您的代码、当前输出和所需的输出,因为不清楚您的问题是什么。 &amp; 是如何被删除的?
  • 关键字:网址编码

标签: facebook perl button share


【解决方案1】:

您需要使用URI::Escape 或一些类似的模块/功能来转义您的查询参数:

use strict;
use warnings;

use URI::Escape;

my %form = ( category => 'car', item => '[]1415689774' );

my $u = "http://www.ibidthai.com/auction.pl?category=$form{'category'}&item=$form{'item'}";

my $url = "http://www.facebook.com/sharer/sharer.php?u=" . uri_escape($u);

print "$url\n";

输出:

http://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fwww.ibidthai.com%2Fauction.pl%3Fcategory%3Dcar%26item%3D%5B%5D1415689774

虽然,如果您想要彻底,如果第一个查询参数可能包含特殊字符,则您的两个 URI 实际上都应该进行编码:

use strict;
use warnings;

use URI;

my %form = ( category => 'car', item => '[]1415689774' );

my $auction_uri = URI->new("http://www.ibidthai.com/auction.pl");
$auction_uri->query_form( category => $form{category}, item => $form{item} );

print "$auction_uri\n";

my $share_uri = URI->new('http://www.facebook.com/sharer/sharer.php');
$share_uri->query_form( u => "$auction_uri" );

print "$share_uri\n";

输出:

http://www.ibidthai.com/auction.pl?category=car&item=%5B%5D1415689774
http://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fwww.ibidthai.com%2Fauction.pl%3Fcategory%3Dcar%26item%3D%255B%255D1415689774

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-19
    • 2014-10-04
    相关资源
    最近更新 更多