Counting paragraphs in a file : fgets « File Directory « PHP
- PHP
- File Directory
- fgets
Counting paragraphs in a file
<?php
$paragraphs = 0;
if ($fh = fopen('great-american-novel.txt','r')) {
while (! feof($fh)) {
$s = fgets($fh);
if (("\n" == $s) || ("\r\n" == $s)) {
$paragraphs++;
}
}
}
print $paragraphs;
?>
Related examples in the same category