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
Here's a non Regex way to do it:
<?php $tweet = "Foo bar #hashTag hello world"; $hashPos = strpos($tweet,'#'); $hashTag = ''; while ($tweet[$hashPos] !== ' ') { $hashTag .= $tweet[$hashPos++]; } echo $hashTag;
Demo
Note: This will only pickup the first hashtag in the tweet.