\n problem

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
shining
Forum Newbie
Posts: 2
Joined: Wed Apr 02, 2003 4:44 pm

\n problem

Post by shining »

First of all please excuse my poor English...

My problem is this:

Code: Select all

echo "This is line1\n This is line 2";

just prints This is line1 This is line 2 (on the same row). Why?


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

Post by volka »

you're creating a html-document, aren't you?
try

Code: Select all

<html><body>
	<p>
		<?php echo "This is line1\n This is line 2"; ?>
	</p>
	<p>
		<?php echo "This is line1<br />\nThis is line 2"; ?>
	</p>

	<pre>
		<?php echo "This is line1\nThis is line 2"; ?>
	</pre>
</body></html>
or without php

Code: Select all

&lt;html&gt;&lt;body&gt;
	&lt;p&gt;
		This is line1
		This is line 2
	&lt;/p&gt;
	&lt;p&gt;
		This is line1 &lt;br /&gt;
		This is line 2
	&lt;/p&gt;

	&lt;pre&gt;
		This is line1
		This is line 2
	&lt;/pre&gt;
&lt;/body&gt;&lt;/html&gt;
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Depending on what you're doing (if you're formatting the source code then ignore me and go back to volka's post), if you're trying to format the display then you may need nl2br():
http://www.php.net/manual/en/function.nl2br.php

Mac
shining
Forum Newbie
Posts: 2
Joined: Wed Apr 02, 2003 4:44 pm

Post by shining »

Thanks you for the answers and once again, please excuse my poor english. I'll be back... after I will learn to write in english :D
Post Reply