Thread View: ba.php
3 messages
3 total messages
Started by Jeroen Straathof
Sun, 13 Aug 2000 00:00
How to Count words?
Author: Jeroen Straathof
Date: Sun, 13 Aug 2000 00:00
Date: Sun, 13 Aug 2000 00:00
16 lines
1228 bytes
1228 bytes
Hello, How do I count words in PHP ? I have version 3.0.17 installed. Regards, Jeroen -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-= Web: http://www.webtoolcentral.com Mail: jeroen@webperfex.nl ICQ: 22792936 WebPager: http://wwp.mirabilis.com/22792936 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=
Re: How to Count words?
Author: Dave Jones
Date: Sun, 13 Aug 2000 00:00
Date: Sun, 13 Aug 2000 00:00
33 lines
1607 bytes
1607 bytes
How about parsing the string into an array and seeing how big the array is? Jeroen Straathof wrote: > > Hello, > > How do I count words in PHP ? > I have version 3.0.17 installed. > > Regards, > > Jeroen > > -- > =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-= > Web: http://www.webtoolcentral.com > Mail: jeroen@webperfex.nl > ICQ: 22792936 > WebPager: http://wwp.mirabilis.com/22792936 > =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-= -- -------------------- To send e-mail to me replace the domain name with djdesign.com The phony "anti.spam" domain is used to fool newsgroup e-mail address harvestor 'bots. ----------------------
Re: How to Count words?
Author: chernyshevsky
Date: Mon, 14 Aug 2000 00:00
Date: Mon, 14 Aug 2000 00:00
52 lines
1879 bytes
1879 bytes
This should work:
function count_word($text)
{
$count = 0;
for($i = 0, $j = -1; $i < strlen($text); $i++)
{
switch($text[$i])
{
case "\r":
case "\n":
case "\t":
case " ":
if($i != $j + 1)
{
$count++;
}
$j = $i;
}
}
if($i != $j + 1)
{
$count++;
}
return $count;
}
Something like sizeof(explode(strtr(...))) doesn't work very well, since it
overcounts when you have consecutive delimiters (e.g. a space before a
linebreak). If you have to loop through the array anyway looking for empty
strings, might as well loop through the string instead.
Jeroen Straathof <jstraa@yahoo.com> wrote in message
news:8n6b5f$f6v$1@porthos.nl.uu.net...
> Hello,
>
> How do I count words in PHP ?
> I have version 3.0.17 installed.
>
> Regards,
>
> Jeroen
>
> --
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=
> Web: http://www.webtoolcentral.com
> Mail: jeroen@webperfex.nl
> ICQ: 22792936
> WebPager: http://wwp.mirabilis.com/22792936
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=
>
>
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads