Increment number in text file
<p>I want to record downloads in a text file</p>

<p>Someone comes to my site and downloads something, it will add a new row to the text file if it hasn't already or increment the current one.</p>

<p>I have tried</p>

<pre><code>$filename = 'a.txt';
$lines    = file($filename);
$linea    = array();

foreach ($lines as $line) 
{ 
    $linea[] = explode("|",$line);
}

$linea[0][1] ++;

$a = $linea[0][0] . "|" . $linea[0][1];

file_put_contents($filename, $a);
</code></pre>

<p>but it always increments it by more than 1</p>

<p>The text file format is </p>

<pre><code> name|download_count
</code></pre>
