1

The table below displays all words in the string $commentstring. How can I exclude certain articles, prepositions, and verbs like "the, of, is"?

$words = explode(" ", $commentstring);

$result = array();
arsort($words);

foreach($words as $word) {    
  if(!is_numeric($word)){
    $result[$word]++;
    arsort($result);
  }
}

echo "<table>";

foreach($result as $word => $count1) {
  echo '<tr>';  
  echo '<td>';
  echo "$word";
  echo '</td>';

  echo '<td>';
  echo "$count1 ";
  echo '</td>';

  echo '</tr>';
}

echo "</table>";
John
  • 4,820
  • 21
  • 62
  • 92

1 Answers1

0

Several ways to do this, if you still want to count them but just not display them in the table, you could do:

$blacklist = array('the', 'is', 'a');

foreach($result as $word => $count1)
{
    if (in_array($word, $blacklist)) continue;

    ...

if you don't even want to count them, you can skip them in a similar way in your counting loop.

Timothée Groleau
  • 1,940
  • 13
  • 16