Code Conventions and preferences

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

    Code Conventions and preferences

    A kind of survey...

    1) what do yo prefer?

    a)
    echo '<table border="1" width="100%" border="0" cellspacing="0" >';
    ?>

    or
    b)
    ?>
    </table>

    I mean, html inside php block or outside?

    regards - jm
  • Shelly

    #2
    Re: Code Conventions and preferences

    I prefer the first if it is surrounded by other php statements. I don't
    like hopping in and out of php.

    Shelly

    "julian maisano" <julianmaisanoX YZ@gmail.com> wrote in message
    news:dbcggi$602 $1@domitilla.ai oe.org...[color=blue]
    >A kind of survey...
    >
    > 1) what do yo prefer?
    >
    > a)
    > echo '<table border="1" width="100%" border="0" cellspacing="0" >';
    > ?>
    >
    > or
    > b)
    > ?>
    > </table>
    >
    > I mean, html inside php block or outside?
    >
    > regards - jm[/color]


    Comment

    • R. Rajesh Jeba Anbiah

      #3
      Re: Code Conventions and preferences

      julian maisano wrote:[color=blue]
      > A kind of survey...
      >
      > 1) what do yo prefer?
      >
      > a)
      > echo '<table border="1" width="100%" border="0" cellspacing="0" >';
      > ?>
      >
      > or
      > b)
      > ?>
      > </table>
      >
      > I mean, html inside php block or outside?[/color]

      Seriously against to (a). Not sure, what is (b). I embed html inside
      PHP and vice versa. I use echo only to output data, but never to output
      html. Mine is:

      <div id="main">
      <?php
      if ($foo)
      {
      ?>
      <p>Condition is true</p>
      <?php
      }
      ?>
      <table summary="<?php echo $foo->getValue('summ ary');?>">
      <tr>
      <td><?php echo $foo->getValue('foo1 ');?></td><td><?php echo
      $foo->getValue('foo2 ');?></td>
      </tr>
      <tr>
      <td><?php echo $foo->getValue('foo3 ');?></td><td><?php echo
      $foo->getValue('foo4 ');?></td>
      </tr>
      </table>
      </div>

      --
      <?php echo 'Just another PHP saint'; ?>
      Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com

      Comment

      • no@emails.thx

        #4
        Re: Code Conventions and preferences

        On Sat, 16 Jul 2005 23:40:55 -0500, julian maisano
        <julianmaisanoX YZ@gmail.com> wrote:[color=blue]
        >A kind of survey...
        >
        >1) what do yo prefer?
        >
        >a)
        >echo '<table border="1" width="100%" border="0" cellspacing="0" >';
        >?>
        >
        >or
        >b)
        >?>
        ></table>
        >
        >I mean, html inside php block or outside?[/color]

        I'd say it is all down to which predominates ... some of my pages are
        purely HTML so they need no PHP. Others might just need a small bit of
        database-derived information or some constants or included blocks etc
        so i have the HTML surrounding one or two small <?php ... ?> areas.
        But if the page is basically all includes and logic or data-derived
        areas then i'd start with a <?php and finish with ?> and then echo
        the HTML inside.

        Basically, I agree with one of the other posters - avoid jumping in
        and out of PHP because it makes the code very hard to follow and debug
        later. Also, it's as much as anything down to readability and
        presenting an intuitive source-code - so think of the person following
        on from you who has to maintain the site - or even yourself a year on.
        Put in plenty of comments describing what the script should do over
        all - and then in more detail before major sections describing perhaps
        why you chose to do the code in such a way.

        Chris

        Comment

        • Chung Leong

          #5
          Re: Code Conventions and preferences

          Echoing HTML from PHP gets tricky when you have any embedded
          Javascript. I usually break out of PHP when there's a large chunk of
          HTML.

          Comment

          • Norman Peelman

            #6
            Re: Code Conventions and preferences


            "Chung Leong" <chernyshevsky@ hotmail.com> wrote in message
            news:1121701181 .036632.42660@g 47g2000cwa.goog legroups.com...[color=blue]
            > Echoing HTML from PHP gets tricky when you have any embedded
            > Javascript. I usually break out of PHP when there's a large chunk of
            > HTML.
            >[/color]

            What happens then???

            Norm
            ---
            Avatar Hosting at www.easyavatar.com


            Comment

            Working...