Hello,
I'm doing a conversion on a csv file and writing out a new version of the file. The conversion works great when I get LF ('\n') or CRLF ('\r\n'), but I'm getting some files with just a CR ('\r') and these are causing me a problems. Because I'm using fgetcsv it isn't finding the line ending for the line and I'm only getting the last line of the file.
I'm guessing there should be a way to convert these line endings to CRLF, but I'm having trouble figuring it out.
Here's my code to do the conversion:
$file_handle = fopen($incomingsales, "r");
while (!feof($file_handle) ) {
$line_of_text = fgetcsv($file_handle, 1024);
$line_of_text = str_replace("$","",$line_of_text);
$line_of_text = str_replace(" ","",$line_of_text);
$new_str[]=$line_of_text[0].",". $line_of_text[1].",0,0,1,".$line_of_text[2].",N";
}
fclose($file_handle);