View Full Version : /n or /r not working.

03-26-2012, 11:10 PM
Just learning php and I was trying to echo two lines if text, one being on one line and the next being on the line below it but I can't get it to work.

What I am using is this:

echo"The file " . basename($_FILES['userfile']['name']) . " has been uploaded.\n";

Then I tried this:

echo"The file " . basename($_FILES['userfile']['name']) . " has been uploaded.\r";

But that doesn't place the second echo on a new line either. What I get is this:

The file test.pdf has been uploaded. The file myimage.jpg has been uploaded.

Can anyone steer me to the correct way to do this?


03-26-2012, 11:12 PM
Try using the br tag instead:

echo"The file " . basename($_FILES['userfile']['name']) . " has been uploaded.<br>";

The \r and \n will change how it looks when you view the source of the web page however.

03-26-2012, 11:12 PM
hint: <br />

03-26-2012, 11:28 PM
Thanks to both oracleguy and litebearer.

I'll use the <br /> but just for my understanding, when would one use the "\r" or "\n" in their code and why?


03-26-2012, 11:55 PM
The \n and \r is used for text formatting not page formatting.

EG in your html SOURCE CODE you will see that they are on different lines but on the WEB PAGE they are not.

Thats because html is a MARKUP language. It doesn't matter where things are, the browser will read the source by the html tags. You could put all the html source on one line if you wanted and as long as the correct tags are in place it would display the same.

03-27-2012, 02:15 AM
hint: <br />

That should be <br> for HTML and <br/> for XHTML - there is no need for the space (unless you are serving the XHTML version as HTML to Netscape 4).

03-27-2012, 02:51 AM
Ok, gotcha!

Thanks felgall and tangoforce.

When learning a language it always helps to know why things are done in a certain way.

Thanks again.