<?php $afile = "data.txt"; if (file_exists ($afile)){ $rows = file ($afile); echo count ($rows) . " lines in this file"; //Outputs 4 in this case } else { echo "Sorry, file does not exist."; } ?>