PHP Twitter replace link and hashtag with real link – Here in this article, we will share some of the most common and frequently asked about PHP problem in programming with detailed answers and code samples. There’s nothing quite so frustrating as being faced with PHP errors and being unable to figure out what is preventing your website from functioning as it should like and . If you have an existing PHP-based website or application that is experiencing performance issues, let’s get thinking about PHP Twitter replace link and hashtag with real link.
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?
Solution :
$str = preg_replace("/@(w+)/i", "<a href="http://twitter.com/$1"">
$0<
/a>
, $str)