PHP Twitter用实际链接替换链接和主题标签 [英] PHP Twitter replace link and hashtag with real link
本文介绍了PHP Twitter用实际链接替换链接和主题标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在遍历Twitter API的JSON响应.每个API响应都会给我一条类似于以下内容的推文:
I am looping over JSON response from Twitter API. Each API response gives me a tweet similar to:
我叫@john,我爱#足球,拜访我
Hi my name is @john, and I love #soccer, visit me
我正在尝试替换@john
,并插入<a href=http://twitter.com/john>@john</a>
,但是在@john
之后的逗号(,
)是问题所在.
I am trying to replace @john
, and insert <a href=http://twitter.com/john>@john</a>
but the comma (,
) after @john
, is the problem.
如何在标签前后替换点,逗号等?
How to replace dots, commas, etc before and after the tag?
推荐答案
$str = preg_replace("/@(\w+)/i", "<a href=\"http://twitter.com/$1\">$0</a>", $str);
这篇关于PHP Twitter用实际链接替换链接和主题标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文