在PHP中从字符串中提取Twitter主题标签

Zei*_*vic 2 php twitter hashtag

我需要一些关于twitter hashtag的帮助,我需要在PHP中提取某个hashtag作为字符串变量.到现在为止,我有这个

$hash = preg_replace ("/#(\\w+)/", "<a href=\"http://twitter.com/search?q=$1\">#$1</a>", $tweet_text);
Run Code Online (Sandbox Code Playgroud)

但这只是将hashtag_string转换为链接

nic*_*ckb 8

使用preg_match()标识哈希,它捕捉到一个变量,就像这样:

$string = 'Tweet #hashtag';
preg_match("/#(\\w+)/", $string, $matches);
$hash = $matches[1];
var_dump( $hash); // Outputs 'hashtag'
Run Code Online (Sandbox Code Playgroud)

演示