How can the file() function in PHP be used to read data from a file line by line for processing?
To read data from a file line by line in PHP, you can use the file() function, which reads the entire file into an array with each element representing a line of the file. You can then loop through this array to process each line individually.
$file = 'data.txt';
$lines = file($file);
foreach ($lines as $line) {
// Process each line here
echo $line;
}
Keywords
Related Questions
- What are some best practices for integrating external graphics, like ICQ buttons, into a PHP website?
- What are the best practices for handling header redirection in PHP to avoid the "Cannot modify header information" error?
- Why is it recommended to use classes instead of IDs for elements when handling events in PHP?