Counting the number of times a character occurs in a very large text file
<p>I would like to count the occurrence of all commas in a very large text file (its has comma delimited data). Size is 28mb. I thought of loading up the text file and doing something like this:</p>

<pre><code>substr_count($text, ',');
</code></pre>

<p>Good idea? Will it work?</p>

<p>The overall task is to find out how many rows of data it has. When I count the number of commas, I will divide this by the number of columns which will give me the number of rows. If there is a better way of doing this, let me know!</p>

<p>Thanks all</p>

<h2>EDIT</h2>

<p>The below worked but is it efficient as the suggestions?</p>

<pre><code>$lines = file('C:\wamp\CE.txt');

$number = 0;

foreach($lines as $line){

   $number = $number + substr_count($line, ',');

}

echo $number;
</code></pre>
