snorpey snorpey - 11 months ago 55
PHP Question

Retrieve all hashtags from a tweet in a PHP function

I want to retrieve all hashtags from a tweet using a PHP function.

I know someone asked a similar question here, but there is no hint how exactly to implement this in PHP. Since I'm not very familiar with regular expressions, don't know how to write a function that returns an array of all hashtags in a tweet.

So how do I do this, using the following regular expression:


$tweet = "this has a #hashtag a  #badhash-tag and a #goodhash_tag";

preg_match_all("/(#\w+)/", $tweet, $matches);

var_dump( $matches );

*Dashes are illegal chars for hashtags, underscores are allowed.