How to process a file line by line in PHP?

In PHP, how to process a file line by line? The file is a plain text line like input.txt. As an example, the process can be to just print it out.

asked May 23, 2017 by dtivl (2,500 points)

1 Answer

In PHP, you can use this code snippet to process a file line by line:

if ( ($fhandle = fopen("./input.txt", "r") !== FALSE ) {
  while (($line = fgets($fhandle)) !== false) {
    echo $line
  }

  fclose($handle);
} else {
  // error handling
} 
answered May 23, 2017 by dtivl (2,500 points)

Please log in or register to answer this question.

Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost

...