takeiteasy Posted June 6, 2007 Share Posted June 6, 2007 Hi all! i need some help here, hope some of u can help! Can someone help me with generating the number of word counts for the following code? That means when i type the words in the textbox, another textbox will show the number of words typed. i'm using php code. Information <b>(max of 50 words):</b> <tr> <td class="td_normal" colspan="2"> <input class="td_normal" type="text" size="50" name="content2" '; if ($FormXEmployerObj) $str.='value="'.$FormXEmployerObj->get(content2).'"'; $str.='> <br> Current Word Count:<tr> <td class="td_normal" colspan="2"> <input class="td_normal" type="text" size="2" name="content3"'; if ($FormXEmployerObj) $str.='value="'.$FormXEmployerObj->get(content3).'"'; $str.='> </td> </tr> Thanks!! Quote Link to comment Share on other sites More sharing options...
chigley Posted June 6, 2007 Share Posted June 6, 2007 <?php function wordcount($string) { $pieces = explode(" ", $string); return count($pieces); } $string = "word1 word2 word3 word4"; $count = wordcount($string); echo "The string \"{$string}\" has {$count} words!"; ?> Can be adapted to suit your needs Quote Link to comment Share on other sites More sharing options...
takeiteasy Posted June 6, 2007 Author Share Posted June 6, 2007 Thanks chigley for your help, but i'm quite new to php...so i dont really know how to adapt my current code with the 1 u gave me..can u pls guide me. thanks!! Quote Link to comment Share on other sites More sharing options...
Dragen Posted June 6, 2007 Share Posted June 6, 2007 do you mean that you want the count to change as you're typing? If so you'll need to use javascript, not php Quote Link to comment Share on other sites More sharing options...
obsidian Posted June 6, 2007 Share Posted June 6, 2007 Thanks chigley for your help, but i'm quite new to php...so i dont really know how to adapt my current code with the 1 u gave me..can u pls guide me. thanks!! A couple things to consider: simply exploding on the spaces, while a great start, is very easily tricked. If you were to type something like a 5 : !, it would be counted as 4 words. Secondly, if you're wanting it to be a live count, you may want to use javascript instead. Quote Link to comment Share on other sites More sharing options...
takeiteasy Posted June 6, 2007 Author Share Posted June 6, 2007 hmm...so can u all help me on the javascript coding? thanks alot! Quote Link to comment Share on other sites More sharing options...
per1os Posted June 6, 2007 Share Posted June 6, 2007 Thats a question for the javascript gurus, not php. Quote Link to comment Share on other sites More sharing options...
obsidian Posted June 6, 2007 Share Posted June 6, 2007 hmm...so can u all help me on the javascript coding? thanks alot! Try something like this: http://javascript.internet.com/forms/word-count.html Quote Link to comment Share on other sites More sharing options...
takeiteasy Posted June 6, 2007 Author Share Posted June 6, 2007 Thanks obsidian for your help, but is there a code that will count the number of words while u type in the textbox? that means we do not need to click the count word button n we'll know the number of words. Quote Link to comment Share on other sites More sharing options...
obsidian Posted June 6, 2007 Share Posted June 6, 2007 Thanks obsidian for your help, but is there a code that will count the number of words while u type in the textbox? that means we do not need to click the count word button n we'll know the number of words. Once you get the word count function working, you'll need to tie it to the onkeypress event on your textarea. Then, you'll need to modify your function slightly to know which area in which to count the words. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.