homepage Welcome to WebmasterWorld Guest from 54.166.113.249
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
line break in csv file
Sarah Atkinson

10+ Year Member



 
Msg#: 9736 posted 5:40 pm on Aug 18, 2005 (gmt 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

 

mcibor

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 9736 posted 5:51 pm on Aug 18, 2005 (gmt 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).

Sarah Atkinson

10+ Year Member



 
Msg#: 9736 posted 6:39 pm on Aug 18, 2005 (gmt 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?

mcibor

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 9736 posted 7:25 pm on Aug 18, 2005 (gmt 0)

$csv = str_replace('rectangle here', '', $csv);
That should do!
michal

Sarah Atkinson

10+ Year Member



 
Msg#: 9736 posted 6:02 pm on Aug 19, 2005 (gmt 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.

mcibor

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 9736 posted 8:51 pm on Aug 19, 2005 (gmt 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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved