html output lines

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

    html output lines

    given that php
    echo '<div>';
    echo 'whatever';
    echo '</div>';
    echo '<div>';
    echo 'whatever';
    echo '</div>';
    echo '<div>';
    echo 'whatever';
    echo '</div>';
    echo '<div>';
    echo 'whatever';
    echo '</div>';


    the output html is

    <div>whatever </div><div>whatev er</div><div>whatev er</div><div>whatev er</div>

    whereas I would like to have as output the following (It's better in
    order to read and understand the html code)

    <div>
    whatever
    </div>
    <div>
    whatever
    </div>
    <div>
    whatever
    </div>
    <div>
    whatever
    </div>

    How should I do ?

    regards - jm

  • fiziwig

    #2
    Re: html output lines

    echo '<div>\n';

    --gary

    Comment

    • julian_m

      #3
      Re: html output lines


      fiziwig wrote:[color=blue]
      > echo '<div>\n';[/color]

      It actually prints \n in the browser, which is what I don't want. I
      just need to add carriage retruns in the html source, not the rendered
      page

      regards - jm

      Comment

      • ED

        #4
        Re: html output lines

        "fiziwig" <fiziwig@yahoo. com> wrote in message
        news:1143224578 .951239.12360@t 31g2000cwb.goog legroups.com...[color=blue]
        > echo '<div>\n';
        >
        > --gary
        >[/color]

        erm, shouldn't that be:
        echo "<div>\n";
        (note: double quotes not single)

        ED


        Comment

        • fiziwig

          #5
          Re: html output lines

          My bad. Double quotes are necessary to that php actually interprets the
          contents of the quotes instead of just echoing it as is.

          --gary

          Comment

          • Justin Koivisto

            #6
            Re: html output lines

            ED wrote:[color=blue]
            > "fiziwig" <fiziwig@yahoo. com> wrote in message
            > news:1143224578 .951239.12360@t 31g2000cwb.goog legroups.com...[color=green]
            >> echo '<div>\n';
            >>
            >> --gary
            >>[/color]
            >
            > erm, shouldn't that be:
            > echo "<div>\n";
            > (note: double quotes not single)[/color]

            or you could define the end of line string in a constant for easier
            modification down the road...

            <?php
            define('CRLF'," \r\n");

            echo '<div>',CRLF;
            ....
            ?>

            --
            Justin Koivisto, ZCE - justin@koivi.co m

            Comment

            • ED

              #7
              Re: html output lines

              true, but you have to type 4 characters every line instead of 2 that way ;-)



              "Justin Koivisto" <justin@koivi.c om> wrote in message
              news:8JidnQxIyO Az8LnZRVn-tA@onvoy.com...[color=blue]
              > ED wrote:[color=green]
              >> "fiziwig" <fiziwig@yahoo. com> wrote in message
              >> news:1143224578 .951239.12360@t 31g2000cwb.goog legroups.com...[color=darkred]
              >>> echo '<div>\n';
              >>>
              >>> --gary
              >>>[/color]
              >>
              >> erm, shouldn't that be:
              >> echo "<div>\n";
              >> (note: double quotes not single)[/color]
              >
              > or you could define the end of line string in a constant for easier
              > modification down the road...
              >
              > <?php
              > define('CRLF'," \r\n");
              >
              > echo '<div>',CRLF;
              > ...
              > ?>
              >
              > --
              > Justin Koivisto, ZCE - justin@koivi.co m
              > http://koivi.com[/color]


              Comment

              • John Dunlop

                #8
                Re: html output lines

                Justin Koivisto:
                [color=blue]
                > or you could define the end of line string in a constant for easier
                > modification down the road...[/color]

                Good idea I reckon...
                [color=blue]
                > define('CRLF'," \r\n");[/color]

                That's circular. Since '\r\n' in double quotes means a CRLF pair,
                define()-ing 'CRLF' as such doesn't better position you. What's worse,
                if the value was to change to one or the other (i.e., to either CR or
                LF, or indeed to something else) then the label 'CRLF' becomes a
                misnomer.

                What is useful to define(), I think, and I believe this was your
                point, is not a label representing a particular 'end of line string'
                but rather the end-of-line itself. (There is a predefined constant,
                namely 'PHP_EOL', that would seem to stand for end-of-line, but I can't
                find any documentation.)

                --
                Jock

                Comment

                • julian_m

                  #9
                  Re: html output lines


                  Justin Koivisto wrote:[color=blue]
                  > ED wrote:[color=green]
                  > > "fiziwig" <fiziwig@yahoo. com> wrote in message
                  > > news:1143224578 .951239.12360@t 31g2000cwb.goog legroups.com...[color=darkred]
                  > >> echo '<div>\n';
                  > >>
                  > >> --gary
                  > >>[/color]
                  > >
                  > > erm, shouldn't that be:
                  > > echo "<div>\n";
                  > > (note: double quotes not single)[/color]
                  >
                  > or you could define the end of line string in a constant for easier
                  > modification down the road...[/color]

                  That's what I did already, thinking in the same scenario, using a var
                  though:
                  $L_end = "\n";
                  [color=blue]
                  > <?php
                  > define('CRLF'," \r\n");
                  >
                  > echo '<div>',CRLF;[/color]

                  It is possible to join two strings with ',' or it was just a typo ???

                  regards - jm

                  Comment

                  • d

                    #10
                    Re: html output lines

                    "julian_m" <julianmaisano@ gmail.com> wrote in message
                    news:1143261736 .826036.238840@ i40g2000cwc.goo glegroups.com.. .[color=blue]
                    >
                    > Justin Koivisto wrote:[color=green]
                    >> ED wrote:[color=darkred]
                    >> > "fiziwig" <fiziwig@yahoo. com> wrote in message
                    >> > news:1143224578 .951239.12360@t 31g2000cwb.goog legroups.com...
                    >> >> echo '<div>\n';
                    >> >>
                    >> >> --gary
                    >> >>
                    >> >
                    >> > erm, shouldn't that be:
                    >> > echo "<div>\n";
                    >> > (note: double quotes not single)[/color]
                    >>
                    >> or you could define the end of line string in a constant for easier
                    >> modification down the road...[/color]
                    >
                    > That's what I did already, thinking in the same scenario, using a var
                    > though:
                    > $L_end = "\n";
                    >[color=green]
                    >> <?php
                    >> define('CRLF'," \r\n");
                    >>
                    >> echo '<div>',CRLF;[/color]
                    >
                    > It is possible to join two strings with ',' or it was just a typo ???[/color]

                    That's not joining strings but passing multiple strings to echo, which is
                    actually a language construct (and not a function), and as such can handle
                    such strangeness.
                    [color=blue]
                    > regards - jm
                    >[/color]


                    Comment

                    Working...