Can't get \n to work.

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

    Can't get \n to work.

    According to zend.com

    Double and single quoted strings are handled differently by PHP. Double
    quoted strings are interpreted while single quoted strings are treated
    exactly as written. For example:

    $foo = 2;
    echo "foo is $foo"; // this prints: foo is 2
    echo 'foo is $foo'; // this prints: foo is $foo
    echo "foo is $foo\n"; // this prints: foo is 2 (with a new-line)
    echo 'foo is $foo\n'; // this prints: foo is $foo\n

    I can not get this to work.

  • petersprc@gmail.com

    #2
    Re: Can't get \n to work.

    Can you paste the code that isn't working? The zend.com tutorial is
    exactly right.

    sk wrote:
    According to zend.com
    >
    Double and single quoted strings are handled differently by PHP. Double
    quoted strings are interpreted while single quoted strings are treated
    exactly as written. For example:
    >
    $foo = 2;
    echo "foo is $foo"; // this prints: foo is 2
    echo 'foo is $foo'; // this prints: foo is $foo
    echo "foo is $foo\n"; // this prints: foo is 2 (with a new-line)
    echo 'foo is $foo\n'; // this prints: foo is $foo\n
    >
    I can not get this to work.

    Comment

    • Chris Hope

      #3
      Re: Can't get \n to work.

      sk wrote:
      According to zend.com
      >
      Double and single quoted strings are handled differently by PHP.
      Double quoted strings are interpreted while single quoted strings are
      treated exactly as written. For example:
      >
      $foo = 2;
      echo "foo is $foo"; // this prints: foo is 2
      echo 'foo is $foo'; // this prints: foo is $foo
      echo "foo is $foo\n"; // this prints: foo is 2 (with a new-line)
      echo 'foo is $foo\n'; // this prints: foo is $foo\n
      >
      I can not get this to work.
      In what way can you not get it to work?

      If you are outputting HTML and viewing it in a web browser, it pays to
      remember that newline breaks are *not* rendered. To render a line break
      in a web browser you need <br / If you view the source of the page
      you'll see those \n line breaks there but not in the normal browser
      window.

      --
      Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com

      Comment

      • .:[ ikciu ]:.

        #4
        Re: Can't get \n to work.

        Hmm sk <someone@somewh ere.orgwrote:
        I can not get this to work.
        Why? There is no error.


        --
        ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~
        Ikciu | gg: 718845 | yahoo: ikciu_irsa | www: www.e-irsa.pl

        2be || !2be $this =mysql_query();


        Comment

        • Gary Hasler

          #5
          Re: Can't get \n to work.

          sk wrote:
          echo "foo is $foo\n"; // this prints: foo is 2 (with a new-line)
          ...
          I can not get this to work.
          I've had the same problem.
          This is a bit clunky but always works for me:

          $cr = '
          ';

          echo "foo is $foo" . $cr;

          Comment

          • Norman Peelman

            #6
            Re: Can't get \n to work.

            <petersprc@gmai l.comwrote in message
            news:1160010036 .756728.4270@h4 8g2000cwc.googl egroups.com...
            Can you paste the code that isn't working? The zend.com tutorial is
            exactly right.
            >
            sk wrote:
            According to zend.com

            Double and single quoted strings are handled differently by PHP. Double
            quoted strings are interpreted while single quoted strings are treated
            exactly as written. For example:

            $foo = 2;
            echo "foo is $foo"; // this prints: foo is 2
            echo 'foo is $foo'; // this prints: foo is $foo
            echo "foo is $foo\n"; // this prints: foo is 2 (with a new-line)
            echo 'foo is $foo\n'; // this prints: foo is $foo\n

            I can not get this to work.
            >
            Sometimes you must add \r to it like so:

            echo "foo is $foo\n\r";

            Norm


            Comment

            • sk

              #7
              Re: Can't get \n to work.

              The following line is the output from the below.

              foo is 2foo is $foofoo is 2 foo is $foo\n

              $foo = 2;
              echo "foo is $foo"; // this prints: foo is 2
              echo 'foo is $foo'; // this prints: foo is $foo
              echo "foo is $foo\n"; // this prints: foo is 2 (with a new-line)
              echo 'foo is $foo\n'; // this prints: foo is $foo\n

              As you can see, no new-line.

              petersprc@gmail .com wrote:
              Can you paste the code that isn't working? The zend.com tutorial is
              exactly right.
              >
              sk wrote:
              >
              >>According to zend.com
              >>
              >>Double and single quoted strings are handled differently by PHP. Double
              >>quoted strings are interpreted while single quoted strings are treated
              >>exactly as written. For example:
              >>
              >>$foo = 2;
              >>echo "foo is $foo"; // this prints: foo is 2
              >>echo 'foo is $foo'; // this prints: foo is $foo
              >>echo "foo is $foo\n"; // this prints: foo is 2 (with a new-line)
              >>echo 'foo is $foo\n'; // this prints: foo is $foo\n
              >>
              >>I can not get this to work.
              >
              >

              Comment

              • sk

                #8
                Re: Can't get \n to work.

                tried following with same results.... no new line

                $foo = 2;
                echo "foo is $foo"; // this prints: foo is 2
                echo 'foo is $foo'; // this prints: foo is $foo
                echo "foo is $foo\n\r"; // this prints: foo is 2 (with a new-line)
                echo 'foo is $foo\n'; // this prints: foo is $foo\n

                Norman Peelman wrote:
                <petersprc@gmai l.comwrote in message
                news:1160010036 .756728.4270@h4 8g2000cwc.googl egroups.com...
                >
                >>Can you paste the code that isn't working? The zend.com tutorial is
                >>exactly right.
                >>
                >>sk wrote:
                >>
                >>>According to zend.com
                >>>
                >>>Double and single quoted strings are handled differently by PHP. Double
                >>>quoted strings are interpreted while single quoted strings are treated
                >>>exactly as written. For example:
                >>>
                >>>$foo = 2;
                >>>echo "foo is $foo"; // this prints: foo is 2
                >>>echo 'foo is $foo'; // this prints: foo is $foo
                >>>echo "foo is $foo\n"; // this prints: foo is 2 (with a new-line)
                >>>echo 'foo is $foo\n'; // this prints: foo is $foo\n
                >>>
                >>>I can not get this to work.
                >>
                >
                Sometimes you must add \r to it like so:
                >
                echo "foo is $foo\n\r";
                >
                Norm
                >
                >

                Comment

                • sk

                  #9
                  Re: Can't get \n to work.

                  That explains it. Thanks much. Can now quit spinning my wheels.

                  Thanks to all.



                  Chris Hope wrote:
                  sk wrote:
                  >
                  >
                  >>According to zend.com
                  >>
                  >>Double and single quoted strings are handled differently by PHP.
                  >>Double quoted strings are interpreted while single quoted strings are
                  >>treated exactly as written. For example:
                  >>
                  >>$foo = 2;
                  >>echo "foo is $foo"; // this prints: foo is 2
                  >>echo 'foo is $foo'; // this prints: foo is $foo
                  >>echo "foo is $foo\n"; // this prints: foo is 2 (with a new-line)
                  >>echo 'foo is $foo\n'; // this prints: foo is $foo\n
                  >>
                  >>I can not get this to work.
                  >
                  >
                  In what way can you not get it to work?
                  >
                  If you are outputting HTML and viewing it in a web browser, it pays to
                  remember that newline breaks are *not* rendered. To render a line break
                  in a web browser you need <br / If you view the source of the page
                  you'll see those \n line breaks there but not in the normal browser
                  window.
                  >

                  Comment

                  • Colin Fine

                    #10
                    Re: Can't get \n to work.

                    sk wrote:
                    According to zend.com
                    >
                    Double and single quoted strings are handled differently by PHP. Double
                    quoted strings are interpreted while single quoted strings are treated
                    exactly as written. For example:
                    >
                    $foo = 2;
                    echo "foo is $foo"; // this prints: foo is 2
                    echo 'foo is $foo'; // this prints: foo is $foo
                    echo "foo is $foo\n"; // this prints: foo is 2 (with a new-line)
                    echo 'foo is $foo\n'; // this prints: foo is $foo\n
                    >
                    I can not get this to work.
                    >
                    And we're all supposed to guess in what way it doesn't work?

                    I'm sorry if this sounds crabby, sk, but it is a bugbear of mine at work
                    as well as here.

                    'I can't get this to work' is as much use as 'My car won't go'.

                    PLEASE, if you ask for assistance, give people the information they need
                    to render assistance: tell them
                    - what you did
                    - what happened (including what you saw)
                    - what system/context you were in
                    - what you expected, if it is not obvious.

                    </lecture>

                    Colin

                    Comment

                    • sk

                      #11
                      Re: Can't get \n to work.

                      Seems like you are only one who had problem understanding only logical
                      'can't get this to work'. However, No new-line!


                      Colin Fine wrote:
                      sk wrote:
                      >
                      >According to zend.com
                      >>
                      >Double and single quoted strings are handled differently by PHP.
                      >Double quoted strings are interpreted while single quoted strings are
                      >treated exactly as written. For example:
                      >>
                      >$foo = 2;
                      >echo "foo is $foo"; // this prints: foo is 2
                      >echo 'foo is $foo'; // this prints: foo is $foo
                      >echo "foo is $foo\n"; // this prints: foo is 2 (with a new-line)
                      >echo 'foo is $foo\n'; // this prints: foo is $foo\n
                      >>
                      >I can not get this to work.
                      >>
                      >
                      And we're all supposed to guess in what way it doesn't work?
                      >
                      I'm sorry if this sounds crabby, sk, but it is a bugbear of mine at work
                      as well as here.
                      >
                      'I can't get this to work' is as much use as 'My car won't go'.
                      >
                      PLEASE, if you ask for assistance, give people the information they need
                      to render assistance: tell them
                      - what you did
                      - what happened (including what you saw)
                      - what system/context you were in
                      - what you expected, if it is not obvious.
                      >
                      </lecture>
                      >
                      Colin

                      Comment

                      • Colin Fine

                        #12
                        Re: Can't get \n to work.

                        sk wrote:
                        Seems like you are only one who had problem understanding only logical
                        'can't get this to work'. However, No new-line!
                        >
                        Oh really?

                        petersrpc said:
                        "Can you paste the code that isn't working? The zend.com tutorial is
                        exactly right."

                        Norman Peelman and Gary Hassler both did guess what problem your were
                        seeing, but since they didn't know you were talking about HTML, their
                        suggestions were irrelevant.

                        Chris Hope asked:
                        "Can you paste the code that isn't working? The zend.com tutorial is
                        exactly right."
                        but did then guess the problem and gave you the solution.

                        ikciu said:
                        "Why? There is no error."

                        So of the six people who replied to you, three of us asked for more
                        information, one said there was no problem (which there isn't, in the
                        code) and three guessed what you might mean. Of those three, two guessed
                        wrong.

                        So actually, far from my being 'the only one who had a problem
                        understanding', Chris Hope was the only one out of six who guessed what
                        the problem was! And he asked for more information.

                        Far from being "the only logical 'can't get this to work'", your missing
                        new-line is nothing whatever to do with your PHP code!

                        Colin

                        Comment

                        Working...