indenting

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

    indenting

    Dear readers,

    If you use some funtion to generate html code like:

    <?
    function display_stuff( parameters)
    {
    echo "<p>\n";
    echo " <table cellspacing=\"0 \" cellpadding=\"0 \" border=\"0\"
    width=\"100%\"> \n";
    /* .. more stuff here... */
    echo " </table>\n";
    echo "</p>\n";
    }
    ?>

    Is there some way to know your 'current horizontal position' so you can
    indent a html section properly?

    Tia, Jean


  • Iván Sánchez Ortega

    #2
    Re: indenting

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    Jean Pion wrote:
    [color=blue]
    > Is there some way to know your 'current horizontal position' so you can
    > indent a html section properly?[/color]

    Ugh.

    You may want to use Output Buffering along with the Tidy functions.



    (And - indenting HTML code is not as important as making clean,
    standards-compliant, valid HTML code).

    - --
    - ----------------------------------
    Iván Sánchez Ortega -i-punto-sanchez--arroba-mirame-punto-net

    http://acm.asoc.fi.upm.es/~mr/ ; http://acm.asoc.fi.upm.es/~ivan/
    MSN:i_eat_s_p_a _m_for_breakfas t@hotmail.com
    Jabber:ivansanc hez@jabber.org ; ivansanchez@kde talk.net
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.2 (GNU/Linux)

    iD8DBQFDu/bY3jcQ2mg3Pc8RA n+dAJ9nKfBduWiH ByebT4SBBh+o6vQ gBQCfc5cD
    8j+DvfHPubYwhvU bgJAdjJc=
    =9zBL
    -----END PGP SIGNATURE-----

    Comment

    • tomb

      #3
      Re: indenting

      Jean Pion wrote:
      [color=blue]
      > Dear readers,
      >
      >If you use some funtion to generate html code like:
      >
      ><?
      >function display_stuff( parameters)
      >{
      > echo "<p>\n";
      > echo " <table cellspacing=\"0 \" cellpadding=\"0 \" border=\"0\"
      >width=\"100%\" >\n";
      > /* .. more stuff here... */
      > echo " </table>\n";
      > echo "</p>\n";
      >}
      >?>
      >
      >Is there some way to know your 'current horizontal position' so you can
      >indent a html section properly?
      >
      > Tia, Jean
      >
      >
      >
      >[/color]
      As Iván alludes to, the great thing about php is you're really writing a
      program, not html. So, in the php commands you'll want neat code. That
      will benefit you when you go back to it. I would recommend also
      including comments about what is going on, so you don't have to try to
      remember 6 months from now. But the only reason to generate neat html
      is so the users can look at the page source and make sense of it more.

      Tom

      Comment

      • Toby Inkster

        #4
        Re: indenting

        Jean Pion wrote:
        [color=blue]
        > Is there some way to know your 'current horizontal position' so you can
        > indent a html section properly?[/color]

        When I care about indentation (which is not very often), I tend to achieve
        it by passing an $indent parameter to the function, which takes a string
        of whitespace and prepends it to each line.

        Example follows...

        =============== =============== =============== ===

        <?php

        function createDiv ($innerText, $indent='')
        {
        $innerText = str_replace("\n ", "\n{$indent } ", $innerText);
        return "{$indent}<div> \n"
        . "{$indent} {$innerText}\n"
        . "{$indent}</div>";
        }

        $divInner = createDiv("Hell o world");
        $divMiddle = createDiv($divI nner);
        $divOuter = createDiv($divM iddle, ' ');

        ?>
        <html>
        <body>
        <?= $divOuter ?>

        </body>
        </html>

        =============== =============== =============== ===

        Which should generate:

        <html>
        <body>
        <div>
        <div>
        <div>
        Hello
        </div>
        </div>
        </div>
        </body>
        </html>

        --
        Toby A Inkster BSc (Hons) ARCS
        Contact Me ~ http://tobyinkster.co.uk/contact

        Comment

        • Iván Sánchez Ortega

          #5
          Re: indenting

          -----BEGIN PGP SIGNED MESSAGE-----
          Hash: SHA1

          tomb wrote:
          [color=blue]
          > But the only reason to generate neat html
          > is so the users can look at the page source and make sense of it more.[/color]

          Besides, a developer should not read raw HTML, but should have a look at the
          DOM tree - there are wonderful DOM tree inspectors for Konqueror and
          Firefox (built-in) and for IE (via third-party toolbars).

          Analyzing the DOM tree generated by the PHP scripts, and validating the
          generated HTML against W3C's validators would prove more useful than
          writing scripts that generate indented HTML.

          (In fact, my programs generate a gibberish of (X)HTML that validates quite
          nicely, but is a mess to read).

          - --
          - ----------------------------------
          Iván Sánchez Ortega -i-punto-sanchez--arroba-mirame-punto-net


          Proudly running Debian Linux with 2.6.12-1-686 kernel, KDE3.5.0, and PHP
          5.0.5-3 generating this signature.
          Uptime: 02:03:19 up 1 day, 4:28, 1 user, load average: 0.43, 0.32, 0.14

          -----BEGIN PGP SIGNATURE-----
          Version: GnuPG v1.4.2 (GNU/Linux)

          iD8DBQFDvHD63jc Q2mg3Pc8RAtDlAJ sH3Lqab9NYhQC3D ift98up+Fv9UQCf alu1
          PUVFbiUKEaDQYAT cGPpmM7M=
          =vvGt
          -----END PGP SIGNATURE-----

          Comment

          • Jean Pion

            #6
            Re: indenting


            "Iván Sánchez Ortega" <i.punto.sanche z--@rroba--mirame.punto.ne t> schreef in
            bericht news:m18u83-u8m.ln1@blacksp ark.escomposlin ux.org...[color=blue]
            > tomb wrote:
            >[color=green]
            >> But the only reason to generate neat html
            >> is so the users can look at the page source and make sense of it more.[/color]
            >
            > Besides, a developer should not read raw HTML, but should have a look at
            > the
            > DOM tree - there are wonderful DOM tree inspectors for Konqueror and
            > Firefox (built-in) and for IE (via third-party toolbars).
            >
            > Analyzing the DOM tree generated by the PHP scripts, and validating the
            > generated HTML against W3C's validators would prove more useful than
            > writing scripts that generate indented HTML.
            >[/color]

            I'm just working on some inherited code, and I don't want to rewrite it
            completely.
            What I do now is load source of the resulting page into CSE Html Validator.
            If would help me a bit to make it more readable;
            but you are right: a comment blocks will do fine.

            Thanks for your input,
            Jean.
            [color=blue]
            >
            > (In fact, my programs generate a gibberish of (X)HTML that validates quite
            > nicely, but is a mess to read).
            >
            > - --
            > - ----------------------------------
            > Iván Sánchez Ortega -i-punto-sanchez--arroba-mirame-punto-net
            >[/color]


            Comment

            Working...