Welcome to WebmasterWorld Guest from 54.160.221.82

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

line break in csv file

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

Preferred Member

10+ Year Member

joined:Apr 29, 2003
posts:424
votes: 0


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?

Sarah

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 26, 2003
posts:1133
votes: 0


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)

Preferred Member

10+ Year Member

joined:Apr 29, 2003
posts:424
votes: 0


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)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 26, 2003
posts:1133
votes: 0


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

Preferred Member

10+ Year Member

joined:Apr 29, 2003
posts:424
votes: 0


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)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 26, 2003
posts:1133
votes: 0


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

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members