Processing a list of books : fgets « File Directory « PHP






Processing a list of books

 
<?php
$fh = fopen('books.txt','r') or die("can't open: $php_errormsg");
while (! feof($fh)) {
    $s = rtrim(fgets($fh));
    list($title,$author,$publication_year) = explode('|',$s);
}
fclose($fh) or die("can't close: $php_errormsg");
?>
  
  








Related examples in the same category

1.Checking for an error from fopen(), fgets(), or fclose()
2.Counting paragraphs in a file
3.Counting records in a file
4.Creating and Using a File Class
5.Reading a compressed file
6.Reading a file a line at a time
7.fgets() function returns a string read from a file.
8.fgets.php
9.Processing each word in a file