Jump to content

Storing Several Words After A Character To Array


jmack549

Recommended Posts

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:

 

if (strpos($message,'#') !== false) {
 $numberofhashtags = substr_count($message, '#');
 if($numberofhashtags > 1)
 {
 $i = 0;
while($numberofhashtags>$i)
{
$trendingwords[$i]=strstr($message, '#');
echo $trendingwords[$i] . "</br>";
$i++;
}
 }
 else
 {
 $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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.