Jump to content

The number of words!


torvald_helmer

Recommended Posts

I have a script that reads all files from a folder and store it in an array(1), then it read the file content of  all the txt-files, removes small words that have no relevanse for the content, and then save all remaining word into an array(2).

 

What can I do to find out how many times a spesific word appears in a txt-file, and in how many of the files this spesific word appear.

 

E.g. the word 'report' appears 7 times in txt-file 1, and also it appear in txt-file number 2 3 14 and 56.

 

I want to for each of my files take the first word in the array(2) and find out how many times it appears in the first txt-file, and then in how many of the other files it also appear (here the number of occurance in each file is not important), then I want to start over with word number to in array(2) and do the whole procedure all over again.

 

Any good tips for me? :)

Link to comment
https://forums.phpfreaks.com/topic/43859-the-number-of-words/
Share on other sites

<?php
$str = "the cat sat on the mat";
$a = str_word_count($str,1);            // create an array of the words
$b = array_count_values($a);           // count the occurences
echo '<pre>', print_r($b, true), '</pre>';
?>

Link to comment
https://forums.phpfreaks.com/topic/43859-the-number-of-words/#findComment-213009
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.