I am using simplehtmldom to grab the html from a site. I then search for all the divs on the page and display the innertext where the word count is greater than 300. To do this I iterate with foreach.
$findDivs = $html->find('div');
foreach($findDivs as $findDiv) {
$wordCount = explode(' ', $findDiv->outertext);
$wordCount = count($wordCount);
if($wordCount <= 300) {
$findDiv->outertext = '';
}
else {
echo $findDiv->outertext . '<br />';
}
}
The problem that I have is that the results are duplicated 6 times. I can only assume that it is because all the divs are looped over for each iteration. However, I am not certain what technique I could use to ensure that each div is only assessed once.