Reputation:
I am fetching mysql data and writing it to xls file, that data contains First Name,Last Name, Email, Address , City, State, Zip.
Every thing is working fine except for the few rows for example
if address string is "1921 s. catalina ave suite 3"
than address field in xls file contains only part of the string "1921 s. catalina" and " ave suite 3" in new line
another example if address string is "22850 crenshaw blvd suite101"
than address field in xls file contains only part of the string "22850 crenshaw blvd" and " suite101" in new line.
I dont know what is breaking address string to two parts
Upvotes: 2
Views: 2103
Reputation: 878
You should be using the fputcsv function to write as CSV. That will take care of the encoding and also escaping weird characters that break the layout. More details on the PHP documentation here.
EDIT: OP wanted a XLS format, not CSV, so the trick was to just clean up the string from newline characters using:
$xls_string = preg_replace("/\r\n|\n\r|\n|\r/", " ", $dirty_string);
Upvotes: 4