Use a $count
variable to keep track.
This should work -
$count = 0;
foreach($lines as $line)
{
// Check if the line contains the string we're looking for, and print if it does
if(strpos($line, $search) !== false){
$count++;
echo '<p> '.$line.' </p>';
}
}
echo $count;