Twitter API,添加超链接
Twitter API, Adding Hyperlinks
我正在使用 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
您可能需要显式设置编码并使用多字节字符串函数:
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);
我正在使用 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
您可能需要显式设置编码并使用多字节字符串函数:
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);