Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Dec 2008
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts

    /n or /r not working.

    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:

    PHP Code:
    echo"The file " basename($_FILES['userfile']['name']) . " has been uploaded.\n"
    Then I tried this:

    PHP Code:
    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?

    Thanks

  • #2
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Try using the br tag instead:
    PHP Code:
    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.
    OracleGuy

  • #3
    Regular Coder
    Join Date
    Apr 2004
    Posts
    298
    Thanks
    0
    Thanked 23 Times in 23 Posts
    hint: <br />

  • #4
    New Coder
    Join Date
    Dec 2008
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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?

    Thanks

  • #5
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,474
    Thanks
    63
    Thanked 537 Times in 524 Posts
    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.
    I can't really think of anything to write here now...

  • #6
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Quote Originally Posted by litebearer View Post
    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).
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #7
    New Coder
    Join Date
    Dec 2008
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •