I have a basic regex function that converts the hastags into links but the problem I have is that it only converts the actual word into a link and leaves the # alone. I want the # to be part of the link… inside the a tag.
What it produces:
#<a href="">hastag</a>
What I want:
<a href="">#hastag</a>
My php code:
public function link_hashtags($text)
{
$text = preg_replace('/(^|\s)#(\w*[a-zA-Z_]+\w*)/', '\1#<a href="http://search.twitter.com/search?q=%23\2">\2</a>', $text);
return $text;
}
It does pass the word correctly as I dont want the hashtag passed to the url, any suggestions?
Thank you!
Put the
#symbol within the<a>tag as you did, but also take out the one preceding the tag…