newlines help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kkbbzzaa
    Member
    • Jul 2004
    • 38

    #1

    newlines help

    I'm trying to print a newline on the code (not HTML) so i tryied this:

    PHP Code:
    echo "firstline\n secondline\n"
    I supposed this will print something like

    firstline
    secondline

    buy instead it prints just:

    firstline\n secondline

    any ideas why?

    thanks

    Mateo
    oxoia.com
  • AndrewT
    Administrator
    • Mar 2004
    • 3655

    #2
    How exactly are you executing this? Using SSH via PHP (CLI) that should work just fine.

    Comment

    • Elite
      Senior Member
      • Apr 2004
      • 168

      #3
      I've always used \r\n for emails from PHP

      HTH

      Comment

      • kkbbzzaa
        Member
        • Jul 2004
        • 38

        #4
        Ok, solved the problem.

        My exact code was:

        PHP Code:
        echo 'firstline\n secondline\n'
        It seems the problem was the simple quotes.

        Solution:

        PHP Code:
        echo 'firstline'."\n".'secondline'."\n"
        i'm confused about this but the problem is solved.

        Thanks a lot

        Mateo
        oxoia.com

        Comment

        • djn
          Senior Member
          • Mar 2004
          • 140

          #5
          That's exactly what PHP is meant to do. Whatever you put between single quotes is considered a plain text string and used without modifications, while double quotes mark a string meant to be parsed for variables and special characters (like newlines and tabs).

          Comment

          • kkbbzzaa
            Member
            • Jul 2004
            • 38

            #6
            Thanks a lot, that is a cool thing to know!
            oxoia.com

            Comment

            Working...