Processing each word in a file : fgets « File Directory « PHP






Processing each word in a file

 
<?php
$fh = fopen('novel.txt','r') or die($php_errormsg);
while (! feof($fh)) {
    if ($s = fgets($fh)) {
        $words = preg_split('/\s+/',$s,-1,PREG_SPLIT_NO_EMPTY);
    }
}
fclose($fh) or die($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 a list of books