Jump to content

Line ending problem with fputcsv


scott.stephan

Recommended Posts

I've never had this problem. I'm sure this is a 100% stupid question, but I'm swamped with about 400 tiny projects and I don't quite have time to do my due diligence on this one.  :(

 

Anyhow- I'm having a problem where when I use fputcsv to create a CSV from my array, it's not reading line breaks and I'm getting a file with one row that's about 10,000 columns/fields long! I've never had this problem with fputcsv before and I'm a little befuddled. Code below:

 

<?php
$handle = fopen("RetailerSpreadsheet.csv", "r");
$row=0; //# of rows
$count=0; //# of fields
$row_complete=""; //String of complete row
$list=array(); //Holds complete rows for output to usable CSV
$c=0; //Array counter
$title=""; //Display title of loc
$address=""; //Display address + address for lat/lon calc
$phone=""; //Phone # is applicable

while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$title=$data[2];
$address=$data[3].",".$data[4].",".$data[5].",".$data[6].",".$data[7].",".$data[8].",".$data[9]; //Going to need a special enclosure to avoid problems with ","
$phone=$data[10];
$row_complete= $title.",".$address.",".$phone ;
$list[$c]=$row_complete;
$c++;
echo "FINAL ROW: $row_complete <br/>";
}


$filename="UpdatedRetailerSheetforStoreLoc.csv";
	  
	  $fp = fopen($filename, 'w');
		fputcsv($fp,$list);
	  fclose($fp);
?>

Link to comment
https://forums.phpfreaks.com/topic/165073-line-ending-problem-with-fputcsv/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.