Advertisement
maha_kaal

count_occurencies_in_array

Jan 8th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.47 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, iconv('UTF-8','ISO-8859-1//TRANSLIT',$temp[$i]));
  15.     }
  16. }
  17. //var_dump($words);
  18. print_r(array_count_values($words));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement