Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

What does \n in PHP do?

Options
  • 13-05-2005 1:04pm
    #1
    Closed Accounts Posts: 546 ✭✭✭


    Hi.

    What does \n in php do?

    [PHP]echo "<TR>\n";[/PHP]

    Thanks :)


Comments

  • Registered Users Posts: 11,987 ✭✭✭✭zAbbo


    New Line


  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    It's a newline character. It means that the next text to be output will start on a new line.

    It's not rendered in HTML pages (It's just whitespace), but it's useful for making the outputted HTML code easy to read, for debugging purposes, or perhaps if you want to parse it.


  • Closed Accounts Posts: 3,322 ✭✭✭Repli


    Echos a new line to the output, so basically when you view the page source after its generated, it will look like

    <TR>
    etc etc etc

    rather than

    <TR>etc etc etc


  • Closed Accounts Posts: 546 ✭✭✭exactiv


    Excellent. Thanks for all the replies lads. :D

    Is there a list of these type of characters available somewhere?


  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    http://ie.php.net/types.string

    About halfway down the page.

    There may be more.


  • Advertisement
  • Closed Accounts Posts: 36 Caixa


    http://us3.php.net/types.string

    Scroll down to "Escaped Characters"


  • Closed Accounts Posts: 63 ✭✭smileyrecords


    it comes from good all C :)

    i generaly dont use it if outputing to html

    print '...some content...<br />';

    does the job

    a few of my friends are nostalgic about C so they still use it, i see how it could be confusing for beginners


  • Registered Users Posts: 4,003 ✭✭✭rsynnott


    it comes from good all C :)

    i generaly dont use it if outputing to html

    print '...some content...<br />';

    does the job

    The raw output must be just lovely. An I hate to think what emails look like... Use \n, it's a good habit.


  • Closed Accounts Posts: 63 ✭✭smileyrecords


    u dont have nothing good to say do u?

    i dont care what the raw output looks like as long as the webpage itself works and doesnt have bugs and is pixel perfect

    xhtml doesnt care how the raw output looks as long as you follow the standard u get no problems


  • Registered Users Posts: 216 ✭✭seo-ireland


    I'm not sure the search engines wll thank you for bulking out the page size with unnecessary <br/> tags though.

    I used to use <br/> a lot in the past but then I discovered the gift from God that is CSS and i have never looked back.


  • Advertisement
  • Closed Accounts Posts: 63 ✭✭smileyrecords


    u right

    i only use <br />on articles not for formating the whole site

    i relly only on stylesheets myself they are very usefull and mixed with some php its easy enough to make modules and reuse them, its being long since i used tables :)

    one weird sideeffect of completely css site is how they come up in googles cache! ugly


  • Registered Users Posts: 216 ✭✭seo-ireland


    Google cache matters not, the added respect Google gives to your nice, small, clean pages in terms of rankings does :)


  • Registered Users Posts: 4,003 ✭✭✭rsynnott


    u dont have nothing good to say do u?

    i dont care what the raw output looks like as long as the webpage itself works and doesnt have bugs and is pixel perfect

    xhtml doesnt care how the raw output looks as long as you follow the standard u get no problems

    Good practice never hurt anyone, and if you ultimately ever have to use the same output you're sending to the page in an email or preformatted tag or any number of other things, you'll be glad you did it.

    Also, some poorly-written HTTP clients choke on super-long lines.


Advertisement