Jump to content


This topic is now archived and is closed to further replies.


just weird

Recommended Posts

Hello readers,
I don't know if anyone can solve this without sitting behind my machine but I'm tripping over my shoe laces here. This is all so simple but still won't work!
my \n to break a line never works. I've tried with print() and echo?
I'm using php5.1.1 on Windows and can't figure it out. Is this bad syntax?...
echo "let's break \n it down!"
I've also tried...
echo "lets try this then \r\n STILL NOTHING!"
The escape isn't displayed but my line doesn't break either?
I've had other weird things cause errors in the past.
I've also tried uninstalling and reinstalling the engine as well as the server.
Is this an OS or server issue?
Sorry for posting something so minor but it has become a problem.

Share this post

Link to post
Share on other sites
How are you viewing this? Through a browser? \n does not effect the html output, view the source (right click) to view the output of....

echo "lets try this then\n STILL NOTHING!"

Share this post

Link to post
Share on other sites
Well I don't know your background knowledge of php/html. so excuse me if i'm obvious.

when you do this:
echo "let's break \n it down!"

you will see this in the browser.

let's break  it down!

But your code will be:

let's break
it down!

If you get where I'm going. I think thats your problem. If you are trying to breakline with \n you wont see it in the browser. So you need br tag. I hope thats what you were trying to do. If not explain a little more of what you want your end result to be.

Share this post

Link to post
Share on other sites
I guess that explains that. I was trying to use it for an easier type up vs. using html. As far as my computer background that goes back about 2 years of on and off recreational reading. Still venturing out to the older stuff and the UNIX basis for reference. Thanks for the answer. 

Share this post

Link to post
Share on other sites
This is becuase web browsers ignores whitespace characters, \n \r etc, howver in actuall fact they are still there, but in your source, right click view source.
The way around this to use nl2br which will conver line breaks/carriage returns in html line break (< br />), which the browser will not ignore. Heres a few examples:

// our demo string:
$str = "This line\n has line breaks and \rcarriage \n\n\nreturns!";

// this wont display the line breaks/carriage returns
echo $str;

echo "<br /><br />";

// however this will:
echo nl2br($str);


Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.