Im trying to see how many times certain words occur within a document
//txt file of words and symbols i want to search for in a document (words are
//separated with a return no spaces before or after the words)
$searchWords = file("include/words.txt");
$content = $contentOrig = "lots of words...";
foreach($searchWords as $word)
{
echo $word . ": ";
echo substr_count($content, $word) . "<br />";
$content = $contentOrig;
}
Nothing fancy yet.. just trying to get it to output on a webpage. Im getting 0's for all the words in the list except if the last word in the list appears it gives me an accurate count for that word. Thanks for looking.
You're not breaking your word list into an array. So let's say you have a newline for each word
word1
word2
word3
You would need to use explode
$wordList = explode("
", $searchWords);
foreach($wordList as $word) {
}
Keep in mind it could also be a space or a as well. Without knowing your text file I can't say.