fork(2) download
  1. <?php
  2.  
  3. $string = "Hello, still2blue. This is your string. This string is repeated";
  4.  
  5. $words_list = str_word_count($string, 1); // this returns the array of words
  6.  
  7. $results = array_count_values($words_list);
  8. foreach($results as $word => $count){
  9. echo sprintf("%-10s %2d", $word, $count) . PHP_EOL;
  10. }
Success #stdin #stdout 0.02s 52432KB
stdin
Standard input is empty
stdout
Hello       1
still       1
blue        1
This        2
is          2
your        1
string      2
repeated    1