PHP微博取代真正的链接,链接,包括hashtag [英] PHP Twitter replace link and hashtag for real link
本文介绍了PHP微博取代真正的链接,链接,包括hashtag的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遍历从Twitter的API JSON响应。每个API响应给了我类似的tweet:
大家好,我的名字是@约翰,我爱#soccer,请访问我
我试图取代@约翰,并插入< A HREF = HTTP://twitter.com/john> @约翰< / A>
而是逗号(,)@约翰后,就是问题所在。
如何前后标记后点,逗号等?
解决方案
$海峡= preg_replace(/ @(\\ w +)/ I,< A HREF = \\的http://twitter.com/$1 \\> $ 0℃; / A>中,$ STR);
I am looping over json response from Twitter api. Each api response gives me a tweet similar to:
Hi my name is @john, and I love #soccer, visit me
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微博取代真正的链接,链接,包括hashtag的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文