Re: counting words.

From: Date: Mon, 07 Apr 2003 02:02:50 +0000
Subject: Re: counting words.
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-142626@lists.php.net to get a copy of this message
I don't see how explode could work because of the multiple blanks. However, the blanks are NOT the problem with str_word_count. The following example produces 6 and 4. $x = "this <b>is</b> a test"; echo str_word_count( $x ).'<br>' .str_word_count( strip_tags( html_entity_decode( $x ) ) ); It would help to have a sample of a string from the database that isn't being counted correctly.. "Sebastian" <sebastian@dslr.net> wrote in message news:003a01c2fc91$41d041a0$a8a13f44@level3... > its very inaccurate, over 10 words off: > > $count = str_word_count(strip_tags($row[12])); > > this is closer but still off: > > $words = explode(' ', strip_tags($row[12])); > $count = count($words); > > cheers, > - Sebastian > > > ----- Original Message ----- > From: "Ron Rudman" <ron@helphosts.com> > > > | It's str_word_count(); > | > | > ----- Original Message ----- > | > From: "Sebastian" <sebastian@dslr.net> > | > | > | hello, > | > | I am trying to count the words from text that is fetched from mysql, It > | works, but it's a little inaccurate.. It's about 5 - 10 words off, My > | guess > | it's probably counting some HTML or something. Is there a more accurate > | way > | of counting words? > | > | $row[12] = strip_tags(strtr($row[12], > | array_flip(get_html_translation_table(HTML_ENTITIES)))); > | $wordcount = preg_match_all("#(\w+)#", $row[12], $match_dummy); > | > | if($wordcount == "0") { > | $count =""; > | } else { > | $count = preg_match_all("#(\w+)#", $row[12], $match_dummy); > | } > >

« previous php.general (#142626) next »