title: CSV: Change One Field Column
body: <p>I have file named <code>test.csv</code> which has 85  fields?</p>
  
  <p>I have to read that file, change 1 column &amp; save it again.</p>
  
  <p>I have below code.</p>
  
  <pre><code>$file_name = "test.csv";
  $infos = array();
  if (($handle = fopen($file_name, "r")) !== FALSE) {
      while (($data = fgetcsv($handle, 0, ",")) !== FALSE) {
          //echo "&lt;pre&gt;";
          //print_r($data);
  
          $cleanURL = cleanUrl($data[6]);
  
          $infos[] = $data[0] . ',' . $data[1] . ',' . $data[2] . ',' . $data[3] . ',' . $data[4] . ',' . $data[5] . ',' . $data[6] . ',' . $data[7] . ',' . $data[8] . ',' . $data[9] . ',' . $data[10] . ',' . $data[11] . ',' . $data[12] . ',' . $data[13] . ',' . $data[14] . ',' . $data[15] . ',' . $data[16] . ',' . $cleanURL . ',' . $data[18] . ',' . $data[19] . ',' . $data[20] . ',' . $data[21] . ',' . $data[22] . ',' . $data[23] . ',' . $data[24] . ',' . $data[25] . ',' . $data[26] . ',' . $data[27] . ',' . $data[28] . ',' . $data[29] . ',' . $data[30] . ',' . $data[31] . ',' . $data[32] . ',' . $data[33] . ',' . $data[34] . ',' . $data[35] . ',' . $data[36] . ',' . $data[37] . ',' . $data[38] . ',' . $data[39] . ',' . $data[40] . ',' . $data[41] . ',' . $data[42] . ',' . $data[43] . ',' . $data[44] . ',' . $data[45] . ',' . $data[46] . ',' . $data[47] . ',' . $data[48] . ',' . $data[48] . ',' . $data[50] . ',' . $data[51] . ',' . $data[52] . ',' . $data[53] . ',' . $data[54] . ',' . $data[55] . ',' . $data[56] . ',' . $data[57] . ',' . $data[58] . ',' . $data[59] . ',' . $data[60] . ',' . $data[61] . ',' . $data[62] . ',' . $data[63] . ',' . $data[64] . ',' . $data[65] . ',' . $data[66] . ',' . $data[67] . ',' . $data[68] . ',' . $data[69] . ',' . $data[70] . ',' . $data[71] . ',' . $data[72] . ',' . $data[73] . ',' . $data[74] . ',' . $data[75] . ',' . $data[76] . ',' . $data[77] . ',' . $data[78] . ',' . $data[79] . ',' . $data[80] . ',' . $data[81] . ',' . $data[82] . ',' . $data[83] . ',' . $data[84] . ',' . $data[85];
          //echo $data[6].'-&gt;'.cleanUrl($data[6]);
          //print_r($data[17]);
      }
      fclose($handle);
  }
  
  $fp = fopen('write.csv', 'w');
  
  foreach ($infos as $info) {
      fputcsv($fp, array($info), ',', ' ');
  }
  
  function cleanUrl($str, $replace = array(), $delimiter = '-') {
      setlocale(LC_ALL, 'en_US.UTF8');
      if (!empty($replace)) {
          $str = str_replace((array) $replace, ' ', $str);
      }
  
      $clean = iconv('UTF-8', 'ASCII//TRANSLIT', $str);
      $clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean);
      $clean = strtolower(trim($clean, '-'));
      $clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean);
  
      return $clean;
  }
  </code></pre>
  
  <p>Is there any sorter way, so i don't need to write 85 columns in <code>#info</code> array? Because i'm going to change only 1 column &amp; write it again.</p>
  
  <p>If i have <strong>Date</strong> 10/10/2016, 10:15 AM.</p>
  
  <p>then it separates both in different column.</p>
  
  <p><code>fputcsv($fp, array($info), ',', ' ');</code> here may be issue.</p>