php includes of <div>'s

Discussion in 'PHP' started by Mister Tut, Jan 11, 2006.

  1. #1
    Hi all,

    Very basic question from a PHP amateur...
    When doing a php include of stuff you want in a DIV, is it more correct to call the include from inside the div tags, or to put the div tags inside the included content?

    Thanks in advance,
     
    Mister Tut, Jan 11, 2006 IP
  2. stuw

    stuw Peon

    Messages:
    702
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #2
    depends what your doing. if the div is part of your page structure then this would make more sense to me:
    <div id="content"><?php include('content.php')?></div>
    Then you can control your site structure from your style sheet
    But there is nothing wrong in having markup in your includes either eg:
    content.php may contain:
    <div class="title"><?php echo 'my title is '.$title?><?div>
     
    stuw, Jan 11, 2006 IP
    Mister Tut likes this.
  3. Mister Tut

    Mister Tut Guest

    Messages:
    837
    Likes Received:
    42
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Ah, yes. Thank you.
    The DIV would be to apply CSS styling, so I guess:
    <div id="content"><?php include('content.php')?></div>
    would be the appropriate solution.

    Have a great night!
     
    Mister Tut, Jan 11, 2006 IP
  4. onlyican.com

    onlyican.com Peon

    Messages:
    206
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    With Includes, PHP grabs that file, places the script in its place.

    So it does not matter if the div is in the include or not.

    Includes are good, for example links.

    If you add a new page or delete a page, instead of changing every page with the updates links, just use one file.

    The only problem with including a div in the include, it that if you want to add something at the bottom of the include, but in the same div, you can't easily.
     
    onlyican.com, Jan 12, 2006 IP
  5. Mister Tut

    Mister Tut Guest

    Messages:
    837
    Likes Received:
    42
    Best Answers:
    0
    Trophy Points:
    0
    #5
    But your code will validate either way?
     
    Mister Tut, Jan 12, 2006 IP
  6. onlyican.com

    onlyican.com Peon

    Messages:
    206
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    yes

    With an include you type in the code
    <?php
    echo "hello";

    include "file.php";
    ?>
    and on file you have
    echo "yes";

    Your script will go up and look like this

    <?php

    echo "hello";
    echo "yes";
    ?>

    and it will print helloyes

    (no breaks)
     
    onlyican.com, Jan 12, 2006 IP
  7. stuw

    stuw Peon

    Messages:
    702
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Yes, it makes no difference if your divs are inside your includes or not.

    But it does make sense to have your page structure (read template) outside of your includes:
    eg
    <div id="content"><? include('content'.php)?></div>
    or
    <div id="content">
    <php
    if ($case==true) {
    include('content'.php);
    } else {
    include('somethingelse'.php)
    }
    ?>
    </div>
     
    stuw, Jan 12, 2006 IP