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
- What are the best practices for handling form submissions in PHP to prevent CSRF attacks and unauthorized data manipulation?
- What is the recommended method for making multiple HTTP requests to external domains in PHP?
- What are some potential pitfalls to be aware of when integrating a PHPKit user database with an UP/Download script?