Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Aug 2002
    Location
    Vancouver, BC
    Posts
    67
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How do I force include page to import at the BOTTOM of page??

    I am trying to use the "INCLUDE" statement to import a html file into one of my other html files. The php file loads the first html file, and then in the php I have an INCLUDE statement to append an outside html into the first html file.

    This is what I have in the php file:

    include('' . $year . '.htm');

    It is importing the outside html file sucessfully HOWEVER its importing it at the TOP of the page rather than the BOTTOM. I need the outside html page to append to the BOTTOM of the first..

    How do I do this??

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,078
    Thanks
    11
    Thanked 98 Times in 96 Posts
    PHP treats includes procedurally, so the included content will appear wherever you include it,

    PHP Code:
    <html>
    <body>
    <?include 'header.html';?>
    blah
    <?include 'footer.html';?>
    </body>
    </html>
    now if say header.html itself includes another file then that will appear before 'blah' above (relative to its inclusion in header.html), nothing you can do about that bar including it in footer.html instead , or instead loading the data into a variable e.g. $content & echo()ing that in you main page wherever you want it.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    New Coder
    Join Date
    Aug 2002
    Location
    Vancouver, BC
    Posts
    67
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ah, but i'm not putting the include in the html itself (otherwise it would need to be .php in order to parse the php inside. I am putting the include in the php file that loads the html file.

  • #4
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,078
    Thanks
    11
    Thanked 98 Times in 96 Posts
    if you include() or require() a file it is irrelevant what the extension is , any content wrapped in <?php ?> tags will be parsed.

    but the same still holds , code is parsed procedurally (even OOP code if you see what I mean) so wherever you include is where it will show.

    If thats not possible then get the data into a variable instead and echo.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #5
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you need to get the information from an include or require statement, you can use the output buffer functions. Any actions preformed while in the output buffer state will not produce output, the output will just be stored, like this:

    PHP Code:
    <?php
    ob_start
    ();
    include(
    "file.html");
    $include_data ob_get_contents();
    ob_end_clean();

    echo 
    $include_data;
    ?>
    This should ouput the contents of "file.html" (you would change file.html to reflect your include page. If you remove the "echo" line you will have the contents stored in $include_data.

  • #6
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,078
    Thanks
    11
    Thanked 98 Times in 96 Posts
    ...or file_get_content(), implode(file()) , fopen/fgets etc

    point is that including where required if possible is the more efficient option (appreciating that this is not always possible)
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #7
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i said include becuase I assumed that the file content would needed to be parsed as php... but yes, if you just include the page where needed it is much more efficient.


  •  

    Posting Permissions

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