word count

Out of context: Reply #8

  • Started
  • Last post
  • 9 Responses
  • squidbrains0

    doesn't account for punctuation. doesn't sub-sort the words with same frequency.

    $file = file_get_contents('./lotta_words... true);
    $words = explode(' ', $file);
    $counts = array();
    foreach($words as $word) {
    if ( ! isset($counts[$word])) {
    $counts["$word"] = 1;
    } else {
    $counts["$word"]++;
    }
    }
    asort($counts);

    foreach($counts as $word => $count) {
    echo "$word : $count<br />";
    }

    • Mine was merely a vague response to a vague query.detritus
    • Oh, I see. Sorry - you're referring to your own code. How stupid of me. Carry on.detritus

View thread