EASY QUESTION

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lloydsmods
Forum Newbie
Posts: 22
Joined: Wed Aug 14, 2002 2:03 pm
Location: NC

EASY QUESTION

Post by lloydsmods »

How do you execute a line break without resorting to the HTML tag <br>?

I've tried "\n" but that doesn't seem to work. It still strings the records together into one big line.

I need to output data from my MySQL database but I need each record to be on its own line and I can't use HTML.

Any suggestions?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

<pre>text</pre> will preserve \n-linebreaks (pre-formatted)
nl2br() is also an option
Tiimmy
Forum Commoner
Posts: 38
Joined: Sat Apr 27, 2002 1:56 am
Location: Australia
Contact:

Post by Tiimmy »

The problem with \n that you could be having might be because you're using echo(), if you are; you'll need to use print() instead.

Code: Select all

&lt;?php
echo "Hello world\n"; // Won't work.
print "Hello world\n"; // Will work.
?&gt;
:lol:
lc
Forum Contributor
Posts: 188
Joined: Tue Apr 23, 2002 6:45 pm
Location: Netherlands

Post by lc »

Depending on your system.... you may want to try \r\n in stead of just \n that solved it for me on windoze systems.
User avatar
sam
Forum Contributor
Posts: 217
Joined: Thu Apr 18, 2002 11:11 pm
Location: Northern California
Contact:

Post by sam »

Tiimmy the \n char should work with both echo and print, I just tested it with php 4.2.1,4.2.2 and 4.3RC2 on windows and 4.2.1 on redhat unix and it worked the same on all three. ;)
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

How can you execute a line break?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Why can't you use HTML?

Mac
Post Reply