I am trying to read data from excel files and then import the data to the database. The problem I am having is excel cell contain line break. It creates new line in the .csv file.
@DasherJun 20.2012 — #You could create the file, and then edit out the line breaks where not wanted, or eliminate the line breaks in excel.. Each line in a csv is terminated with a line break.
@bsmbahamasJun 20.2012 — #you could also use $rows = file('filename.csv'); to create an array from each row,
then use $rows = array_map('trim',$rows); to remove all the line breaks, you will be left
with an array named $rows containing all of the rows from the csv file. you can just loop through the $rows array an insert them one at a time at that point, or you can use implode to combine them back into one long string like this $str = implode($rows,"|");
in this case i used pipe characters '|' to seperate them, but you could use whatever you like if you only want to do a single insert
$rows = file('filename.csv'); //create an array from each row in the .csv file
$rows = array_map('trim',$rows); //trim whitespace from the front and back of each row of data
you can use a for(){} or foreach(){} loop to go through the array
$str = implode($rows,"|"); //optionally convert the array back into one long string seperated by pipe chars
@NogDogJun 20.2012 — #If it is a properly formatted CSV file and if you are using fgetcsv() to parse it, newlines within a field should not be a problem.