Storing several words after a character to array

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)
$trendingwords = strstr($message, ‘#’);
$trending=“INSERT INTO trending (word, count) VALUES(’$trendingwords’, ‘0’)”;
mysql_query($trending) or die(mysql_error());

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?

Please post a working example of what you have so far (and what you need it to be)

Well, PHP contains thousands of routines for juggling all kinds of data.
There is a routine for counting occurrences of words in strings.
Here is a link to the PHP manual that explains it. Perhaps this will save you some looping…

Hope that helps…

Sponsor our Newsletter | Privacy Policy | Terms of Service