What is the purpose of the fgets function in PHP?

The fgets function in PHP is used to read a single line from a file. It is commonly used in file handling operations to read data from a file line by line. This function is useful when you need to process a file line by line rather than reading the entire file at once.

$file = fopen("example.txt", "r");

while(!feof($file)) {
  $line = fgets($file);
  echo $line . "<br>";
}

fclose($file);