Php 将twitter散列标签转换为链接和指向可单击链接的链接

Php 将twitter散列标签转换为链接和指向可单击链接的链接,php,Php,我正在用PHP创建Twitter结果列表,我已经在用PHP将返回字符串中的文本链接转换为可点击链接,而不是纯文本 在一些Twitter结果中,字符串包含哈希标记,即以字符开头的文本 我想做的是把hastag转换成一个可点击的链接 例如: Hello my name is Dan, and im working with the #twitter api 我想变成: Hello my name is Dan, and im working with the <a href="http://

我正在用PHP创建Twitter结果列表,我已经在用PHP将返回字符串中的文本链接转换为可点击链接,而不是纯文本

在一些Twitter结果中,字符串包含哈希标记,即以字符开头的文本

我想做的是把hastag转换成一个可点击的链接

例如:

Hello my name is Dan, and im working with the #twitter api
我想变成:

Hello my name is Dan, and im working with the <a href="http://search.twitter.com/search?q=%23twitter">#twitter</a> api
请注意,在URL中,我必须更改为%23-我认为是编码还是解码

还有

我已经在使用下面的代码在字符串中创建可点击的链接,是否可以合并两个正则表达式

以下是我的PHP,用于将链接转换为可点击链接:

            //Convert links in string to links
            preg_match('/(http:\/\/[^\s]+)/', $row["content"], $text);
            $hypertext = "<a target='_blank' href=\"". $text[0] . "\">" . $text[0] . "</a>";
            $newString = preg_replace('/(http:\/\/[^\s]+)/', $hypertext, $row["content"]);
$str = preg_replace('/\#([a-z0-9]+)/i', '<a href="http://search.twitter.com/search?q=%23$1">#$1</a>', $str);
$str = preg_replace(array($url_pattern, $hash_pattern), array($url_replacement, $hash_replacement), $str);