04-04-2004, 07:24 AM
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??
04-04-2004, 08:29 AM
PHP treats includes procedurally, so the included content will appear wherever you include it,
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.
04-04-2004, 08:34 AM
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.
04-05-2004, 08:41 AM
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.
04-05-2004, 01:08 PM
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:
$include_data = ob_get_contents();
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.
04-05-2004, 04:28 PM
...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)
04-05-2004, 04:43 PM
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.