【问题标题】:Sharing content on Facebook not displaying correctly在 Facebook 上分享的内容无法正确显示
【发布时间】:2014-02-05 10:58:56
【问题描述】:

我遇到的一个问题是我的标题包含一个“&”,但当我点击分享时它显示为“&”。

我遇到的另一个问题是下面的代码无法识别“
”或“\n”。

如何让它能够识别“&, ', -, etc..”以及换行符。

<?php
$gettitle = get_the_title();
$getcontent = get_the_content();
$content = substr($getcontent, 0, 20);
$content .= "<br>".$moretexthere;
$link = get_permalink();

$title=urlencode($gettitle);
$url=urlencode($link);
$summary=urlencode($content);
?>

<a onClick="window.open('http://www.facebook.com/sharer.php?s=100&amp;p[title]=<?php echo $title;?>&amp;p[summary]=<?php echo $summary;?>&amp;p[url]=<?php echo $url; ?>','sharer','toolbar=0,status=0,width=548,height=325');" href="javascript: void(0)">Share</a>

【问题讨论】:

    标签: php facebook wordpress share


    【解决方案1】:

    嗯,我用这个作为分享者的 url..

    https://www.facebook.com/sharer/sharer.php?u=URLENCODEDURL
    

    【讨论】:

      【解决方案2】:

      使用urlencode PHP 函数。

      "这个函数在编码字符串时很方便 查询 URL 的一部分..."

      http://php.net/urlencode

      WordPress 示例:

      <?php echo urlencode(get_the_title()); ?>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-10-24
        • 1970-01-01
        • 1970-01-01
        • 2011-09-01
        • 2016-02-27
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多