SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
Thread: count words in a textbox
-
Dec 15, 2000, 01:33 #1
- Join Date
- Jul 2000
- Posts
- 69
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
hi,
Does anybody know how to count the words in a <Textarea> posted to a php script?
basically each word is separated by a space " " so i think using the explode() function to get an array of the words, but i'm not sure how to approach this. Can somebody help?
Thanks
Sang N.
-
Dec 15, 2000, 03:59 #2
- Join Date
- Jul 1999
- Location
- Derbyshire, UK
- Posts
- 4,411
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
This should do the job for you.
<?php
$a = explode( ' ', $textArea );
$numWords = count( $a );
?>
or to put it all on one line:
<?php
$numWords = count( explode( ' ', $textArea ) );
?>
Edit:
Obviously the textarea has name="textArea" and $numWords stores the number of words.Karl Austin :: Profile :: KDA Web Services Ltd.
Business Web Hosting :: Managed Dedicated Hosting
Call 0800 542 9764 today and ask how we can help your business grow.
-
Dec 15, 2000, 19:38 #3
- Join Date
- Jul 2000
- Posts
- 69
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
thanks
Bookmarks