How can file() be used to read a file line by line in PHP?
To read a file line by line in PHP, you can use the file() function which reads the entire file into an array where each element represents a line of the file. You can then loop through this array to process each line individually.
$filename = 'example.txt';
$lines = file($filename);
foreach ($lines as $line) {
echo $line;
}
Keywords
Related Questions
- How important is it to consider the start time when calculating progress or percentages in PHP?
- How can a PHP developer ensure that all entries from a database are correctly displayed using document.write in a loop?
- Are there any potential pitfalls to be aware of when using the ORDER BY clause in PHP to sort data from a database table?