PHP replace data only in one column of csv
<p>I need to replace the values only from the third column in my csv. And no where else.
Column 3 of my csv contains only a 'J' or a'N' and i need to change them to '5' or '0'. But right now i it changes always all found N's and J#s in the whole file. But i need it only updated in the third column. </p>

<p>I use the following code to open and rewrite my csv. But it writes always all found Letters to 5 or 0.</p>

<pre><code>$csvfile = 'csvfile.csv';
if (file_exists($csvfile)) {
        unlink($csvfile);
    echo "Alte $csvfile entfernt!";
} else {
    echo "Keine alte $csvfile vorhanden";
}

$row = 0;
$fp = fopen('csvfile.csv', 'w');
if (($handle = fopen("oldCSV.csv", "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 200000, ",")) !== FALSE) {
    $num = count($data);
    $dataold = ['J', 'N'];                                                            
    $datanew = ['5', '0'];
    echo "&lt;p&gt; $num Felder in Zeile $row: &lt;br /&gt;&lt;/p&gt;\n";
    $row++;
    for ($c=0; $c &lt; $num; $c++) {
        fputs($fp, str_replace($dataold, $datanew, $data[$c] . "\n"));
    }
  }
}

fclose($fp);
</code></pre>