Problem echoing \r\n

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • andy.z@blueyonder.com

    #1

    Problem echoing \r\n


    If I set a varaible as

    $EOL = "\r\n"

    But then want to echo that to a HTML page to see the above string
    i.e. \r\n

    by doing: echo($EOL);

    How do I do it?

    I've tried quotemeta, addslashes and htmlspecialchar
    but can't seem to work it out.

    thanks

    Andy
  • Mike Roetgers

    #2
    Re: Problem echoing \r\n

    andy.z@blueyond er.com schrieb:
    If I set a varaible as
    >
    $EOL = "\r\n"
    >
    But then want to echo that to a HTML page to see the above string
    i.e. \r\n
    >
    by doing: echo($EOL);
    >
    How do I do it?
    >
    I've tried quotemeta, addslashes and htmlspecialchar
    but can't seem to work it out.
    >
    thanks
    >
    Andy
    It should work with single quotes:
    $EOL = '\r\n';
    echo $EOL;

    That should output:
    \r\n

    Comment

    • Darko

      #3
      Re: Problem echoing \r\n

      On Apr 2, 2:08 pm, Mike Roetgers <miker...@infor matik.uni-bremen.de>
      wrote:
      and...@blueyond er.com schrieb:
      >
      >
      >
      If I set a varaible as
      >
      $EOL = "\r\n"
      >
      But then want to echo that to a HTML page to see the above string
      i.e. \r\n
      >
      by doing: echo($EOL);
      >
      How do I do it?
      >
      I've tried quotemeta, addslashes and htmlspecialchar
      but can't seem to work it out.
      >
      thanks
      >
      Andy
      >
      It should work with single quotes:
      $EOL = '\r\n';
      echo $EOL;
      >
      That should output:
      \r\n
      and, of course, it should (and does) work as you've described - with
      the combination of addslashes and htmlspecialchar s, although it will
      work fine with just addslashes, but it isn't formally correct. So you
      should do echo htmlspecialchar s(addslashes("\ r\n"));

      Comment

      • Toby A Inkster

        #4
        Re: Problem echoing \r\n

        andy.z wrote:
        If I set a varaible as
        >
        $EOL = "\r\n"
        >
        But then want to echo that to a HTML page to see the above string
        i.e. \r\n
        >
        by doing: echo($EOL);
        Do you mean that you want the page to have the exact string:

        backslash, r, backslash, n

        ??

        If so, then use 'single quotes' when setting $EOL, not "double quotes".

        --
        Toby A Inkster BSc (Hons) ARCS
        Contact Me ~ http://tobyinkster.co.uk/contact
        Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

        * = I'm getting there!

        Comment

        • andy.z@blueyonder.com

          #5
          Re: Problem echoing \r\n

          In article <1175518348.456 064.252090@e65g 2000hsc.googleg roups.com>,
          darko.maksimovi c@gmail.com says...
          and, of course, it should (and does) work as you've described - with
          the combination of addslashes and htmlspecialchar s, although it will
          work fine with just addslashes, but it isn't formally correct. So you
          should do echo htmlspecialchar s(addslashes("\ r\n"));
          >
          >
          >
          Not what I'm asking Darko.

          Andy

          Comment

          • andy.z@blueyonder.com

            #6
            Re: Problem echoing \r\n

            In article <euqrmh$btq$1@k ohl.informatik. uni-bremen.de>,
            mikeroet@inform atik.uni-bremen.de says...
            >
            It should work with single quotes:
            $EOL = '\r\n';
            echo $EOL;
            >
            That should output:
            \r\n
            >
            Yes but it's no use to me with single quotes.
            The variable is set with double quotes.

            $EOL = "\r\n"

            I want to echo that variable AS IF - it had been set with single quotes.

            Andy

            Comment

            • andy.z@blueyonder.com

              #7
              Re: Problem echoing \r\n

              In article <hr87e4-i1u.ln1@ophelia .g5n.co.uk>,
              usenet200703@to byinkster.co.uk says...
              andy.z wrote:
              >
              If I set a varaible as

              $EOL = "\r\n"

              But then want to echo that to a HTML page to see the above string
              i.e. \r\n

              by doing: echo($EOL);
              >
              Do you mean that you want the page to have the exact string:
              >
              backslash, r, backslash, n
              >
              ??
              >
              If so, then use 'single quotes' when setting $EOL, not "double quotes".
              >

              As shown above in the example I gave - the variable is set with double
              quotes.


              I want to echo it as a string.

              Andy

              Comment

              • Toby A Inkster

                #8
                Re: Problem echoing \r\n

                andy.z wrote:
                I want to echo that variable AS IF - it had been set with single quotes.
                In the general case, there's no way of doing that -- double-quoted strings
                are interpolated and unescaped as soon as they are encountered, and after
                that there's no way of going back to the original string.

                However, in this specific case, addcslashes() should do the trick.

                --
                Toby A Inkster BSc (Hons) ARCS
                Contact Me ~ http://tobyinkster.co.uk/contact
                Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

                * = I'm getting there!

                Comment

                • Rami Elomaa

                  #9
                  Re: Problem echoing \r\n

                  andy.z@blueyond er.com kirjoitti:
                  If I set a varaible as
                  >
                  $EOL = "\r\n"
                  >
                  But then want to echo that to a HTML page to see the above string
                  i.e. \r\n
                  >
                  by doing: echo($EOL);
                  >
                  How do I do it?
                  >
                  I've tried quotemeta, addslashes and htmlspecialchar
                  but can't seem to work it out.
                  >
                  thanks
                  >
                  Andy
                  $EOL = "\\r\\n";

                  --
                  Rami.Elomaa@gma il.com
                  "Olemme apinoiden planeetalla."

                  Comment

                  • andy.z@blueyonder.com

                    #10
                    Re: Problem echoing \r\n

                    In article <o9g7e4-i1u.ln1@ophelia .g5n.co.uk>,
                    usenet200703@to byinkster.co.uk says...
                    >
                    In the general case, there's no way of doing that -- double-quoted strings
                    are interpolated and unescaped as soon as they are encountered, and after
                    that there's no way of going back to the original string.
                    >
                    However, in this specific case, addcslashes() should do the trick.
                    >
                    >
                    Nice - I missed that one in the documentation - that tiny 'c' was
                    probably too small for my eyes to see (bad eyesight)

                    Its a very interesting function anyway.
                    Thanks Toby I'll give that a go.

                    Andy.


                    Comment

                    • andy.z@blueyonder.com

                      #11
                      Re: Problem echoing \r\n

                      In article <eur7vm$6ug$1@n yytiset.pp.htv. fi>, rami.elomaa@gma il.com
                      says...
                      $EOL = "\\r\\n";
                      >
                      No.

                      Comment

                      • Aerik

                        #12
                        Re: Problem echoing \r\n

                        On Apr 2, 9:07 am, and...@blueyond er.com wrote:
                        In article <eur7vm$6u...@n yytiset.pp.htv. fi>, rami.elo...@gma il.com
                        says...
                        >
                        $EOL = "\\r\\n";
                        >
                        No.
                        Whaddya mean, "No." ?

                        Are you trying to say you can't control how the $EOL variable is set -
                        you want a function to take "\r\n" and turn it into somoe output that
                        shows as \r\n in a browser? If so, you'll have to write a function.

                        Comment

                        Working...