473,480 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to check specific words in a textarea?

Hello,
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
  1. $commentaar = trim($_POST['commentaar']);
  2.  
  3. function commenteva($commentaar)
  4.     {
  5.         global $commentaar;
  6.         $commentaar = nl2br($commentaar); //newlines    
  7.  
  8.         $positive = array("goed", "top", "beste"); //Positive words
  9.         $negative = array("slecht", "kut", "beter", "zuigt", "haat"); //Negative words
  10.  
  11.         $plengte = strlen($positief);
  12.         $nlengte = strlen($negatief);
  13.  
  14.         echo ("<br />Aantal positieve woorden: " . $plengte);
  15.         echo ("<br />Aantal negatieve woorden: " . $nlengte);
  16.  
  17.             if($plengte > $nlengte)
  18.             {
  19.                 echo("<br />Commentaar is positief");
  20.             }
  21.             elseif($nlengte > $plengte)
  22.             {
  23.                 echo("<br />commentaar is negatief");
  24.             }
  25.             else
  26.             {
  27.             echo("<br />commentaar is neutraal");
  28.             }
  29.     }
  30.  
  31.  
I just can't get it to work, each try I get different errors, I hope I am clear enough.

Thanks
Oct 28 '10 #1
1 2701
JKing
1,206 Recognized Expert Top Contributor
Have a look at this function.
PHP preg_match_all()

It checks for a pattern inside a string and returns the number of matches.
Oct 29 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
2392
by: Rob Meade | last post by:
Lo all, Ok - I'm adding site search functionality to a database driven website. I have a list of 390 stop/ignore words, having looked at ASPFAQ already I see that the example uses an array,...
2
6029
by: Barti | last post by:
is there any way to check if any textarea or textfield exists in current document fg function checkifexist(){ if any textarea or textfield exist return true else return false } Barti
2
2148
by: Branden | last post by:
hi guys, i was wondering if it is possible to extract selected words in a field to be put in different fields automatically. Do i have to write the code in vb? This is what im trying to do....
1
1259
by: Toska | last post by:
Hi Wonder how the should use the Regex members to add markup code to words in a text. Code: -------------------- string words1 = "dog|cat|pig|horse|hippo";
4
1648
by: MN | last post by:
Hello all - I'm really at wits end on this as I'm not having much success with locating a function or other options I have. I'm working on a message board for a website and I'm needing to check...
5
2744
by: akelly_image | last post by:
Okay, if anyone could toss me some idea's here, please bare with my noobish questions, I just picked up VB2005 Pro about a week ago. ( no prior VB at all ) Here's my issue.. I'm pulling...
1
2278
by: reecevdm | last post by:
Hi, is it possible to have to match a specific word and change the color of that word? What I need to do, is for a content, the color needs to be black. But if a specific word is matched in the...
1
3816
by: sejal17 | last post by:
hello everyone, I have a problem to find a specific words from url.How can we find specific words from url?pls answer me as soon as possible.......
2
1627
pradeepjain
by: pradeepjain | last post by:
Hii, I want to check for empty textarea with javascript ..say only blank space must also be treated as empty textarea...how to do it..is there any script for this .
2
2815
pradeepjain
by: pradeepjain | last post by:
http://www.electrictoolbox.com/jquery-count-words-textarea-input/ hi guys i want to build a autocomplete feature in a textarea . so i thought of like when ever the word count increases call the...
0
7034
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7076
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6732
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5324
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4472
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2990
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2976
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1294
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
174
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.