$file = fopen("myfile.txt", "r"); while(!feof($file)) { $line = fgets($file); // do something with the line } fclose($file);
$lines = file("myfile.txt"); foreach($lines as $line) { // do something with the line }This code uses the file() function to read the entire contents of the file into an array. Each element of the array contains a line from the file. The package library used for file I/O in PHP is the Core PHP package.