【问题标题】:Twitter API, Adding HyperlinksTwitter API,添加超链接
【发布时间】:2015-07-13 22:26:03
【问题描述】:

我正在使用 Twitter API 使用“statuses/user_timeline”函数来抓取我时间线的最后 3 条推文。它抓取推文并发送响应,但我需要在我的网页中为 HTML 注入超链接。问题是 Microsoft 字符正在丢弃链接位置的索引。

Join us at TOMORROW at @SugarLandtxgov's “Art In The Park” and see the 4  
#PODA2 containers all in one place! http://t.co/leqtqhdAiI #HOUarts

[text] => Join us at TOMORROW at @SugarLandtxgov's “Art In The Park” and
see the 4 #PODA2 containers all in one place! http://t.co/leqtqhdAiI 
#HOUarts

[url] => http://t.co/leqtqhdAiI
[expanded_url] => http://www.artshound.com/event/detail/441912984
[display_url] => artshound.com/event/detail/4…
[indices] => Array
       (
              [0] => 109
              [1] => 131
       )

这是我将超链接注入字符串后的输出:

Join us at TOMORROW at @SugarLandtxgov's “Art In The Park” and see the 4 
#PODA2 containers all in one pla<a href="http://t.co/leqtqhdAiI" 
target="_blank">ce! http://t.co/leqtqh</a>dAiI #HOUarts

【问题讨论】:

  • 我的第一印象是,它可能是多字节字符的计数错误(即 UTF-16 而不是 UTF-8),但链接 href 匹配正确,所以可能不是?你能告诉我们你的代码吗?

标签: php html twitter


【解决方案1】:

您可能需要显式设置编码并使用多字节字符串函数:

mb_internal_encoding('UTF-8');
header('Content-type: text/html; charset=UTF-8');
echo mb_substr($text, 0, 109) . '<a href="' . $link . '">' . mb_substr($text, 109, 131-109) . '</a>' . mb_substr($text, 131);

【讨论】:

    猜你喜欢
    • 2013-08-27
    • 2010-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-13
    • 2020-05-08
    • 2014-07-25
    • 1970-01-01
    相关资源
    最近更新 更多