You can use the count function to count how many elements of an array they are. So you simply just add to this array each time, and then count it.
<?php
$dfile = fopen("/usr/share/dict/words", "r");
//Create an empty array
$array_to_count = array();
while(!feof($dfile)) {
$mynextline = fgets($dfile);
if (preg_match("/lly/", $mynextline)){
echo "$mynextline<br>";
//Add it to the array
$array_to_count[] = $mynextline;
}
}
//Now we're at the end so show the amount
echo count($array_to_count);
?>
A simpler way if you don't want to store all of the values (which might come in handy, but anyway) is to just increment to an integer variable like so:
<?php
$dfile = fopen("/usr/share/dict/words", "r");
//Create an integer variable
$count = 0;
while(!feof($dfile)) {
$mynextline = fgets($dfile);
if (preg_match("/lly/", $mynextline)){
echo "$mynextline<br>";
//Add it to the var
$count++;
}
}
//Show the number here
echo $count;
?>