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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.