first of all: Excuse me for some bad English you might experience during the reading of this.
So I made this form with an textarea, people can write a comment in here but I wanted to create something that my function counts specific words in it and says:
Word 1: 12 times
Word 2: 3 times
etc
etc
Code of what I have so far (I'm still a beginner in PHP):
Expand|Select|Wrap|Line Numbers
- $commentaar = trim($_POST['commentaar']);
- function commenteva($commentaar)
- {
- global $commentaar;
- $commentaar = nl2br($commentaar); //newlines
- $positive = array("goed", "top", "beste"); //Positive words
- $negative = array("slecht", "kut", "beter", "zuigt", "haat"); //Negative words
- $plengte = strlen($positief);
- $nlengte = strlen($negatief);
- echo ("<br />Aantal positieve woorden: " . $plengte);
- echo ("<br />Aantal negatieve woorden: " . $nlengte);
- if($plengte > $nlengte)
- {
- echo("<br />Commentaar is positief");
- }
- elseif($nlengte > $plengte)
- {
- echo("<br />commentaar is negatief");
- }
- else
- {
- echo("<br />commentaar is neutraal");
- }
- }
Thanks