Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function jnews_count_words( $str ) {
- $OUT = 0;
- $IN = 1;
- $state = $OUT;
- $wc = 0; // word count
- $i = 0;
- // Scan all characters one by one
- while ($i < strlen($str))
- {
- // If next character is
- // a separator, set the
- // state as OUT
- if ($str[$i] == " " ||
- $str[$i] == "\n" ||
- $str[$i] == "\t")
- $state = $OUT;
- // If next character is not a
- // word separator and state is
- // OUT, then set the state as
- // IN and increment word count
- else if ($state == $OUT)
- {
- $state = $IN;
- ++$wc;
- }
- // Move to next character
- ++$i;
- }
- return $wc;
- }
Advertisement
Add Comment
Please, Sign In to add comment