473,385 Members | 1,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

\r and \r\n does not work!

Hi im trying to create a csv file from a db and insert a new line for
each row. All the resources i can find say that the use of \r or the
use of \r\n are sufficient to generate new lines. However after trying
this for many hours i have come to the conclusion that this is not the
case. Can anyone suggest a better method for generating line breaks? or
tell me what additional code i may require to create line breaks in my
csv file?

regards

Marc

Jun 12 '06 #1
4 2703
"monomaniac21" <mc******@googlemail.com> wrote in message
news:11**********************@u72g2000cwu.googlegr oups.com...
Hi im trying to create a csv file from a db and insert a new line for
each row. All the resources i can find say that the use of \r or the
use of \r\n are sufficient to generate new lines. However after trying
this for many hours i have come to the conclusion that this is not the
case. Can anyone suggest a better method for generating line breaks? or
tell me what additional code i may require to create line breaks in my
csv file?

Could you please show your code sample. There might be something else that
is causing the problem, not \r\n itself. For example there is a difference
between using single quotes '\r\n' and double quotes "\r\n", only the latter
form generates a linebreak.

Another situation where linebreaks are often thought to be missing, is when
you echo something to html code with linebreaks, which mysteriously
disappear because any linebreaks in html are interpreted as whitspace and
therefore reduced to a single space.

<html><body><pre>
<?php echo "here \r\n are \r\n some \r\n linebreaks \r\n for \r\n you"; ?>
</pre></body></html>

There is also a difference between different operating systems to what is a
linebreak. As I recall it, CR is for Mac, LF is for Linux and Windows uses a
combination of the two, CRLF. It's one of those things I'd fix in the world
if I had three wishes.

You might also do this:
$crlf = "
"; // now the variable $crlf contains one linebreak.

// you can insert it into doublequote strings and it works:
$character = "Fred{$crlf}Flintstone";

HTH

--
"ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" -lpk
sp**@outolempi.net | Gedoon-S @ IRCnet | rot13(xv***@bhgbyrzcv.arg)
Jun 12 '06 #2
Thanks kimmo that's really helpful i never knew of the existence of the
<pre> tag.

Kimmo Laine wrote:
"monomaniac21" <mc******@googlemail.com> wrote in message
news:11**********************@u72g2000cwu.googlegr oups.com...
Hi im trying to create a csv file from a db and insert a new line for
each row. All the resources i can find say that the use of \r or the
use of \r\n are sufficient to generate new lines. However after trying
this for many hours i have come to the conclusion that this is not the
case. Can anyone suggest a better method for generating line breaks? or
tell me what additional code i may require to create line breaks in my
csv file?

Could you please show your code sample. There might be something else that
is causing the problem, not \r\n itself. For example there is a difference
between using single quotes '\r\n' and double quotes "\r\n", only the latter
form generates a linebreak.

Another situation where linebreaks are often thought to be missing, is when
you echo something to html code with linebreaks, which mysteriously
disappear because any linebreaks in html are interpreted as whitspace and
therefore reduced to a single space.

<html><body><pre>
<?php echo "here \r\n are \r\n some \r\n linebreaks \r\n for \r\n you"; ?>
</pre></body></html>

There is also a difference between different operating systems to what is a
linebreak. As I recall it, CR is for Mac, LF is for Linux and Windows uses a
combination of the two, CRLF. It's one of those things I'd fix in the world
if I had three wishes.

You might also do this:
$crlf = "
"; // now the variable $crlf contains one linebreak.

// you can insert it into doublequote strings and it works:
$character = "Fred{$crlf}Flintstone";

HTH

--
"ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" -lpk
sp**@outolempi.net | Gedoon-S @ IRCnet | rot13(xv***@bhgbyrzcv.arg)


Jun 12 '06 #3
"monomaniac21" <mc******@googlemail.com> wrote:

Thanks kimmo that's really helpful i never knew of the existence of the
<pre> tag.


If you are really generating a pure text file, forget about <pre> and just
specify Content-Type: text/plain instead of text/html.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jun 14 '06 #4
For outputting plain text, I always do this:

<?php
header('Content-Type: text/plain');
// Send this header so that browsers won't treat it as HTML
echo "row1,row2,row3,row4\r\n"; // Use double quotes!
echo "row1,row2,row3,row4\r\n";
echo "row1,row2,row3,row4\r\n";
echo "row1,row2,row3,row4\r\n";
echo "row1,row2,row3,row4\r\n";
echo "row1,row2,row3,row4\r\n";
?>

Jun 14 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Jonas | last post by:
This works fine in Win XP but does not work at all in Win 98. Private WithEvents objIExplorer As InternetExplorer I have to do it like this to get it to work in Win 98 Dim objIExplorer As...
3
by: Julian | last post by:
Hi I am trying to update a date field in my table but some how this simple code does not work, I know the select work because if I write the fields, it will show the data from the table but why...
5
by: me | last post by:
I have a Class Library that contains a Form and several helper classes. A thread gets created that performs processing of data behind the scenes and the Form never gets displayed (it is for debug...
22
by: Robert Bralic | last post by:
CAN anybody tell me any address where I can download some small(1000-2000) lines C++ proghram source. Or send me ,a small(1000-2000) lines C++ program source that I can compille with gpp under...
12
by: Frank Hauptlorenz | last post by:
Hello Out there! I have a DB2 V7.2 Database (Fix11) on Win 2000 Professional. It was before a NT 4 based Domain - now it is a Win 2000 Domain. The database server is a domain member. Now...
0
by: Jarod_24 | last post by:
How does tabindex work in ASP .net pages I dosen't seem to work quite like in regular forms. and there isn't any TabStop property either. 1 .How do you prevent a control form beign "tabbed"....
14
by: Anoop | last post by:
Hi, I am new to this newsgroup and need help in the following questions. 1. I am workin' on a GUI application. Does C# provides Layout Managers the way Java does to design GUI? I know that it...
89
by: Cuthbert | last post by:
After compiling the source code with gcc v.4.1.1, I got a warning message: "/tmp/ccixzSIL.o: In function 'main';ex.c: (.text+0x9a): warning: the 'gets' function is dangerous and should not be...
14
by: webEater | last post by:
I have a problem, it's not browser specific, and I don't get a solution. I have an (X)HTML document, I show you a part of it: .... <!--<div class="pad">--> <div id="eventImages"><img src=""...
1
by: =?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?= | last post by:
I get the above error in some of the ASP.NET web applications on a server, and I need some help figuring out how to deal with it. This is a rather long post, and I hope I have enough details that...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.