2

在本页面...

http://www.axisofeco.com/matters/2010/03/11/the-word-youre-looking-for-is-sublime/

...我有一个“Tweet this”链接,该链接粘贴在文章标题中,并且链接到您的 Twitter 更新框(如果您已登录 Twitter)。

问题是,当上述文章中包含特殊字符(主要是花哨的单引号/双引号)时,Twitter 似乎无法处理它们。这是 Twitter 尝试(并且非常失败)粘贴到 Twitter 更新框中的内容:

8217;重新+寻找+寻找+是+“崇高”+ http://is.gd/acIW2

(如果上述行中的引号实际上看起来不错,相信我,当 Twitter 尝试处理它们时,它们会保持编码!)

用于格式化 Twitter 更新的相关 PHP 是这样的:

$url = str_replace(' ', '+', $url); 
echo htmlentities($url, ENT_COMPAT, 'UTF-8');

我尝试过使用不同的函数,例如使用 urlencode(),但似乎没有以“Twitter 友好”的方式对字符串 ($url) 进行编码。

4

1 回答 1

1

一个简单urlencode()的为我工作:

发推文

//make sure you only urlencode the get var
echo urlencode("The word you’re looking for is “sublime”");
//ran the above on php and used the result in the link

但是,我只是在形成 URL 之前用普通引号替换“漂亮”引号。根据浏览器/位置的不同,生成的推文对其他用户来说可能看起来不正确。

于 2010-03-11T23:56:21.553 回答