I am trying to count how many times a certain character shows up in a string, and store the immediate word afterwards into an array. Something like Twitter, it’s a project where I have to store “hashtag” words to a “trending” array. Here’s what I have now:
[php]if (strpos($message,’#’) !== false) {
$numberofhashtags = substr_count($message, ‘#’);
if($numberofhashtags > 1)
{
for($i=0;$numberofhastags>$i;$i++)
{
???
}
}
else
{
$trendingwords = strstr($message, ‘#’);
$trending=“INSERT INTO trending
(word
, count
) VALUES(’$trendingwords’, ‘0’)”;
mysql_query($trending) or die(mysql_error());
}[/php]
I obviously can’t figure the loop portion out though, because when the strstr it takes EVERYTHING after the #, not just the next word. So it’s taking the full sentence. I can’t find any other solution that will work for this. Any ideas?