Results 1 to 2 of 2

Thread: Putting all your HTML within PHP

  1. #1
    Join Date
    Mar 2005
    Posts
    83

    Putting all your HTML within PHP

    I've been building websites for about 10 year now, and generally when I do, I tend to keep as much HTML out of the PHP as I can. i.e., if I wanted to loop through an array and generate a list item I would...

    Code:
    <html>
    <title>Title in here</title>
    <head>
    </head>
    <body>
    <h1>A list of stuff</h1>
    <select name="list">
    <?php
    $listArray = array('item1','item2','item3','item4');
    foreach ($listArray as $listArray) {
    ?>
    <option><?= $listArray['title']; ?></option>
    <?php
         } // END foreach
    ?>
    </select>
    </body>
    </html>
    Recently I've been working on a project which involved working on someone elses code, and I've found the whole thing absolutely terrible to work with. This guy seems to put as much HTML as possible within PHP code....like this....

    Code:
    <html>
    <title>Title in here</title>
    <head>
    </head>
    <body>
    <?php
    echo "<h1>A list of stuff</h1>";
    echo "<select name=\"list\">";
    
    $listArray = array('item1','item2','item3','item4');
    foreach ($listArray as $listArray) {
    
    echo "<option><?= $listArray['title']; ?></option>";
    
         } // END foreach
    
    echo "</select>";
    ?>
    </body>
    </html>
    So I'm wondering, is it perfectly normal, which way is best? I find my way easy because when I look at a layout in Dreamweaver, I can see where the list item is in a div or table. If I had a list item in a table, I could clearly see it, but this other guy would put the list item and the table inside php echo's.

    Am I right in thinking that it's unnecessary php code for PHP to parse? Or is there some major benefit in doing it the other guys way.

  2. #2
    Join Date
    Jun 2008
    Location
    cardiff
    Posts
    77
    i can see no advantage, its just lazy coding
    www.uk-site-design.co.uk stylish website development by Mke Dodd from £49.99

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •