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 ensuring data integrity when inserting or updating records in a MySQL database using PHP?
- Are there any specific PHP functions or libraries that can assist with writing and formatting XML data effectively?
- What are some best practices for organizing PHP files and folders for easier maintenance and development?