maha_kaal

occurencies

Jan 9th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.48 KB | None | 0 0
  1. <?php
  2. if(!defined("STDIN")) {
  3. define("STDIN", fopen('php://stdin','r'));
  4. }
  5. echo "Count Occurences of word in a file \n\n";
  6. $filename = 'st.txt';//(string) $_SERVER['argv'][1];
  7. echo "\n";
  8. $file = file($filename);
  9. $words = [];
  10.  
  11. foreach($file as $line){
  12.     $temp = explode(' ', $line);
  13.     for($i = 0; $i < count($temp); $i++){
  14.         array_push($words, $temp[$i]);
  15.         $words[$i] = utf8_encode($words[$i]);
  16.     }
  17. }
  18. var_dump($words);
  19. print_r(array_count_values($words));
Advertisement
Add Comment
Please, Sign In to add comment