Twitter API,添加超链接

时间:2015-05-04 13:45:17

标签: php html twitter

我正在使用Twitter API使用“statuses / user_timeline”功能获取我的时间轴的最后3条推文。它抓取推文并发送响应,但我需要在我的网页中为HTML注入超链接。问题是微软角色正在抛弃链接位置的索引。

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

1 个答案:

答案 0 :(得分: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);