I'm trying to develop a PHP application where it takes comments from users and then match the string to check if the comment is positive or negative. I have list of negative words in negative.txt file. If a word is matched from the word list, then I want a simple integer counter to increment by 1. I tried the some links and created the a code to check if the comment has is negative or positive but it is only matching the last word of the file.Here's the code what i have done.

```
    <?php 
    function teststringforbadwords($comment) 
    {
      $file="BadWords.txt";
      $fopen = fopen($file, "r");
      $fread = fread($fopen,filesize("$file"));
      fclose($fopen);
      $newline_ele = "\n";
      $data_split = explode($newline_ele, $fread);
      $new_tab = "\t";
      $outoutArr = array();
      //process uploaded file data and push in output array
      foreach ($data_split as $string)
      {
          $row = explode($new_tab, $string);
          if(isset($row['0']) && $row['0'] != ""){
              $outoutArr[] = trim($row['0']," ");
          }
      }
      //---------------------------------------------------------------
        foreach($outoutArr as $word) {

        if(stristr($comment,$word)){
            return false;
        }
    }
    return true;
}

    if(isset($_REQUEST["submit"]))
    {
        $comments = $_REQUEST["comments"];
        if (teststringforbadwords($comments)) 
        {
            echo 'string is clean';
        }
        else
        {
            echo 'string contains banned words';
        }
    }
    ?>

```

Link Tried : [Check a string for bad words?](https://stackoverflow.com/questions/5615146/check-a-string-for-bad-words)