Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

line break in csv file

5:40 pm on Aug 18, 2005 (gmt 0)

10+ Year Member

I'm trying to write a script that will display the text for the db in csv format. so I can take the text it echo and save it in a .csv file then open that file in excel. (Because of pesky noncomputer people who refuse to change their habits or learn new things the standerd csv format will not work.)

Ok so I have my data in a db.
and I have an excel file that is formated the way she wants it. so I export the data from excel to .csv and the mysql data to .csv and compair the two(OMG what a difference)

Now I'm trying to create a script that will make the mysql data look like the stuff that comes out of excel.

My problem is the line breaks in the csv from excel they apear as rectangles. how do I get php to echo those (unicode?)rectangles?


5:51 pm on Aug 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Open the file under linux and see if it is ^M. If yes, then it's \r\n if not then it's \n

Or just copy them and paste :)
But as I recall my excel reads this:
while ($row = mysql_fetch_assoc($result)) {
$csv .= implode(";", $row)."\n";

best regards
Michal Cibor

PS. The problem with excel might be that eg. in Poland the separator is ; and , is for numbers, whereas in England , is a separator and for numbers is a . (dot).

6:39 pm on Aug 18, 2005 (gmt 0)

10+ Year Member

ok so now i have it that when I import into excel I get an extra row between rows and I get those rectangles in the excel file. So I either need to change my script or anyone know how to delete those rectangles from excel with one step instead of backspacing them all?
7:25 pm on Aug 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

$csv = str_replace('rectangle here', '', $csv);
That should do!
6:02 pm on Aug 19, 2005 (gmt 0)

10+ Year Member

What are these rectangles? The only way I have figured out how to get them in is to add my own tag "[break]" to the csv file then open it in notepad and use the find/replace. I then C/P the rectange from another file that has it into the replace field.
8:51 pm on Aug 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

You use a notepad - that explains the rectangles! The rectangle sign is every sign that notepad doesn't recognize. Therefore it's ASCII from 1 to 30, moreover unix line break (it's one or two rectangles). There are some more signs that notepad won't recognize, but I think this explains things a bit to you.

See you round!
And best regards
Michal Cibor


Featured Threads

Hot Threads This Week

Hot Threads This Month