This is causing me to lose hair. For some reason I can not get fputcsv to write $output to $converted. I have tried everything except the correct one, I have also tried fwrite(), it works, but will not put a break at the end of the line. I am sure this is something simple.

Thanks!
Chuck

$file_handle = fopen("xrwholesalePipeDelimited.txt", "r");
$converted = fopen("inventoryconverted.txt","w");
while (!feof($file_handle) ) {

$line_of_text = fgets($file_handle);
$column = explode('|', $line_of_text);
//Remove manfacturers used in category field//
$search = $column[12];
$subject = $column[3];
$replace = "";
$replace3 = ";;";
$search2 = "Bulk Packaged Products;";
$search3 = "Bulk Packaged Products";
$search4 = "Retail Display Packaged;";
$search5 = "Retail Display Packaged";
$search6 = ";";
if ($search!="0"){
$removed = str_replace($search,$replace,$subject);
$nopackaging = str_replace($search2,$replace,$removed);
$nopackaging1 = str_replace($search3,$replace,$nopackaging);
$nopackaging2 = str_replace($search4,$replace,$nopackaging1);
$nopackaging3 = str_replace($search5,$replace,$nopackaging2);}

$output=$column[0]."|".$column[1]."|".$column[2]."|".$nopackaging3."|".$column[4]."|".$column[5]."|".$column[6]."|".$column[7]."|".$column[8]."|" .$column[9]."|".$column[10]."|".$column[11]."|".$column[12]."|".$column[13]."|".$column[14]."|".$column[15]."|".$column[16]."|".$column[17]."|"."<BR>";
echo $output;
fputcsv($converted, $output, '|');
//fwrite($conveted, $output); this works but makes on consecutive line.
}

fclose($file_handle);
fclose($converted);

    fputcsv() is expecting the 2nd argument to be an array, which it then breaks up with the specified separator as per the CSV protocol. You are supplying it with an already formatted string.

    $output = array(
       $column[1],
       $column[2],
       $nopacking3,
       $et_cetera
    );
    fputcsv($converted, $output, '|');
    
      Write a Reply...