Turn a twitter hash tag into a link and links to clickable links

lekkhjilbbgbe

New Member
Im creating a list of Twitter results in PHP, im already using PHP to turn text links in the string returned into clickable links rather than plain text.In some of the Twitter results the string contains hash tags, simply text prepended with the # character.What i would like to do is take the hastag and convert it into a clickable link.For instance:\[code\]Hello my name is Dan, and im working with the #twitter api\[/code\]Which I want to turn into:\[code\]Hello my name is Dan, and im working with the <a href="http://search.twitter.com/search?q=%23twitter">#twitter</a> api\[/code\]Notice that in the URL I have to change the # to %23 - I think encode or decode.Also....Im already using the following code to create clickable links within the string, is it possible to combine the two RegEx's?Here is my PHP to convert links to clickable links:\[code\] //Convert links in string to links preg_match('/(http:\/\/[^\s]+)/', $row["content"], $text); $hypertext = "<a target='_blank' href=http://stackoverflow.com/"". $text[0] . "\">" . $text[0] . "</a>"; $newString = preg_replace('/(http:\/\/[^\s]+)/', $hypertext, $row["content"]);\[/code\]
 
Back
Top