I need some help with twitter hashtag, I need to extract a certain hashtag as string variable in PHP. Until now I have this
$hash = preg_replace ("/#(\\w+)/", "<a href=\"http://twitter.com/search?q=$1\">#$1</a>", $tweet_text);
but this just transforms hashtag_string into link
I think this function will help you:
You can use
preg_match_all()
PHP functionwill give you only hastag array
will give you hastag and without hastag array
As i understand you are saying that in text/pargraph/post you want to show tag with hash sign(#) like this:- #tag and in url you want to remove # sign because the string after
#
is not sended to server in request so i have edited your code and try out this:-You can extract a value in a string with preg_match function
preg_match will store matching results in an array. You should take a look at the doc to see how to play with it.
Here's a non Regex way to do it:
Demo
Note: This will only pickup the first hashtag in the tweet.
Extract multiple hashtag to array