Newlines don't work.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lister

    Newlines don't work.

    Hi,

    I am trying to output a newline, but this doesn't work:

    echo "Line1\nLin e2";

    Before anyone says, I know HTML doesn't recognise newlines. I don't
    need newlines in the rendered HTML, I need newlines in the SOURCE to
    make it understandable.

    Cheers,
    Lister

  • Vincent

    #2
    Re: Newlines don't work.

    echo("line1\n") ;
    echo("line2");

    or

    <?php
    $str = <<<EOD
    Example of string
    spanning multiple lines
    using heredoc syntax.
    EOD;
    echo($str);
    ?>

    lister schreef:
    Hi,
    >
    I am trying to output a newline, but this doesn't work:
    >
    echo "Line1\nLin e2";
    >
    Before anyone says, I know HTML doesn't recognise newlines. I don't
    need newlines in the rendered HTML, I need newlines in the SOURCE to
    make it understandable.
    >
    Cheers,
    Lister
    >

    Comment

    • Michael Fesser

      #3
      Re: Newlines don't work.

      ..oO(lister)
      >I am trying to output a newline, but this doesn't work:
      >
      >echo "Line1\nLin e2";
      It does work. What PHP version do you use?

      Micha

      Comment

      • Rik

        #4
        Re: Newlines don't work.

        Vincent <newsgroup@home art.cjb.netwrot e:
        lister schreef:
        >Hi,
        > I am trying to output a newline, but this doesn't work:
        > echo "Line1\nLin e2";
        > Before anyone says, I know HTML doesn't recognise newlines. I don't
        >need newlines in the rendered HTML, I need newlines in the SOURCE to
        >make it understandable.
        > Cheers,
        >Lister
        echo("line1\n") ;
        echo("line2");
        >
        or
        >
        <?php
        $str = <<<EOD
        Example of string
        spanning multiple lines
        using heredoc syntax.
        EOD;
        echo($str);
        ?>
        While I'm a fan of heredoc, just using single quotes will also work.
        --
        Rik Wasmus

        Comment

        • CH4:D

          #5
          Re: Newlines don't work.

          Michael Fesser wrote:
          .oO(lister)
          >
          I am trying to output a newline, but this doesn't work:

          echo "Line1\nLin e2";
          >
          It does work. What PHP version do you use?
          >
          Micha
          I find it weird too. The syntax is correct.

          --

          Comment

          • Christoph Burschka

            #6
            Re: Newlines don't work.

            CH4:D schrieb:
            Michael Fesser wrote:
            >
            >
            >>.oO(lister)
            >>
            >>
            >>>I am trying to output a newline, but this doesn't work:
            >>>
            >>>echo "Line1\nLin e2";
            >>
            >>It does work. What PHP version do you use?
            >>
            >>Micha
            >
            >
            I find it weird too. The syntax is correct.
            >
            Yes, it should only cause a problem if it were enclosed in single
            quotes. '\n' will just print \n, "\n" will print a linebreak. This can't
            work:

            echo 'Line1\nLine2';

            (Just clarifying, since this distinction wasn't yet mentioned.)

            --
            CB

            Comment

            Working...