GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 08-Jan-2006, 22:55
fallen_samurai fallen_samurai is offline
Awaiting Email Confirmation
 
Join Date: Oct 2005
Location: Wisconsin, USA
Posts: 29
fallen_samurai is on a distinguished road

Word Counter


I am trying to create an efficient word counter in the box that is more or less fool proof. For instance, where people can't just keep pressing return to add extra words, or fool the space delimited nature of the counter by putting infinite number of spaces with no actual words. This is what I have so far, this system is totally fallible at the moment.

PHP Code:

<?
if (!empty($_POST['test'])) {
$symbols = array(".",";",":",",");
$word = str_replace($symbols," ",$_POST['test']);
$word = explode(' ',$_POST['test']);
$count = count($word);
echo "This textarea contains ".$count." number of words.";
}
else {
echo "There are no words in this textarea.";
}
?>


The symbols array does not seem to work.
If someone where to type:

This is a test:
message.

It only counts the first 4 words, but it supposed to str_replace ":" with a space. Obviously that part doesn't work either... My major concern is getting an accurate count in the box without fooling it or exploiting it, and also being able to count lines separated by other punctuations (: , ; .), as in that top example should return 5 words, not 4. Can anyone offer some advice on this topic?
  #2  
Old 10-Jan-2006, 23:53
fallen_samurai fallen_samurai is offline
Awaiting Email Confirmation
 
Join Date: Oct 2005
Location: Wisconsin, USA
Posts: 29
fallen_samurai is on a distinguished road

Re: Word Counter


Nevermind...I got it to work, even got a javascript active counter to work. But now I have another problem. I'll refer this to a different post.
  #3  
Old 15-Jan-2006, 06:43
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough

Re: Word Counter


Sorry I didn't reply sooner fallen_samurai, but I have been busy.

I had something like this written a long, LONG time ago but I never used it (it was meant for gidsearch.com). It may not be exactly what you were looking for but I hope it helps you in some small way if you decide to rewrite the script.

PHP Code:

/**
 * Converts any string into a string that can be used as SE-friendly filenames or URLS e.g.
 * converts: <samp>My Telephone Number: +603 5555-5555.</samp> into
 * <samp>my-telephone-number-603-5555-5555</samp>.
 * 
 * @param        string $string The string to convert.
 * @param        string $replace_non_alphanum optional The string or character to replace all NON-ALPHANUMERIC characters. Default is NULL.
 * @param        string $replace_space optional The string or character to replace all spaces.  Default is '-'.
 * @return        string
 */
function gid_seo_string( $string, $replace_non_alphanum=null, $replace_space='-' )
{
    $string    = preg_replace( '~[^a-z0-9_\-\s]~', $replace_non_alphanum, strtolower(trim($string)) );
    return( preg_replace('~\s+~', $replace_space, $string) );
} 


 
 

Recent GIDBlogLast Week of IA Training by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding a word in a 2d grid The_Kingpin C Programming Language 4 24-Feb-2005 19:53
won't read file from disk, dunno why wbsquared03 C++ Forum 3 29-Nov-2004 11:19
How to do word comparison in C++ ? mail_as C++ Forum 19 22-Jun-2004 17:39
testing word file "need help" alexandro C Programming Language 2 03-Jun-2004 14:38
coding a word with a givin factor funnyf C++ Forum 2 13-Jan-2004 08:32

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 22:13.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.