RE: [PHP] Counting Words In a String

From: Date: Mon, 23 Apr 2001 04:08:40 +0000
Subject: RE: [PHP] Counting Words In a String
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-49801@lists.php.net to get a copy of this message
> I want to check a string and return the amount of words present > in it. These > strings could be quite large, some higher than 100,000 > characters. I realize > I could explode the string on the whitespace and count the number > of values. > However, I'm not sure this would be the most optimized way to do this, > especially considering there will be some quite large strings passed. Any > ideas on the most efficient to count the number of words in a > large string? $string = "Here is a very long string"; $array = explode(" ", $string); $count = sizeof($array); echo $count; ------------------------------------------------------------------------ destiney - (des-ti-ny) - n. 1. deity of all things "html", 2. common internet addict, 3. lover of late 80's heavy metal music, 4. Activist for the terminally un-elite; see also - cool guy, des, mr. php... It's 4:00am, your web site is still up, why are you? http://phplinks.org/ http://destiney.com/ ------------------------------------------------------------------------

« previous php.general (#49801) next »