For some answers in this section: I say this: Do not reinvent the wheel.
In PHP use:
str_word_count ( string $string [, int $format [, string $charlist ]] )
format
0 = Returns only the number of words;
1 = Returns an array;
2 = Returns an associative array;
charlist:
Charlist are the characters that you think are words.
Function.str-word-count.php
[ATTENTION]
No one knows anything about the size of your file contents, if your file contents are large, there are many flexible solutions.
(^ ‿◕)
source share