What is the purpose of using a flag when reading a text file in PHP?
When reading a text file in PHP, using a flag is important to keep track of the current position within the file. This allows you to control where you are reading from and easily navigate through the file. Flags can help you read the file sequentially, skip to a specific line, or reset the pointer back to the beginning of the file.
$file = fopen("example.txt", "r");
if ($file) {
while (($line = fgets($file)) !== false) {
// Process each line of the file
}
fclose($file);
}