Mega Code Archive

 
Categories / Php / File Directory
 

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; ?>