hi everyone,
I need to open 2 external files in order to do some calculations.
- how many lines of text are in each file
- how many lines of text contain “examplestring” for each file.
I have created an array with the filenames and a foreach loop.
Question 1 works. I have the linecount nicely displayed in html for each file.
However I’m unable to get Question 2 working. Anyone can help please?
[php]
$files= array(“namefile1”, “namefile2”);
foreach ($files as $file) {
$filename = “data/”.$file.".txt";
$handle = fopen($filename, “r”);
$linecount = 0;
while(!feof($handle)){
$line = fgets($handle);
$linecount++;
echo substr_count($line, “examplestring”);
}
echo “
” . basename($filename, “.txt”) . ": " . PHP_EOL;
echo $linecount . “
}[/php]