[web] Including php files?

Started by
3 comments, last by Krisc 19 years, 2 months ago
Hi, I have arrived at a wall: I have PHP that strings multiple files together into a $text variable. Within that $text variable I want to include more PHP files. How can I do that? It looks like this (pseudo code): header.php: $text = "start"; index.php include(header.php) $text .= "middle [want to include a php file here]"; include(footer.php) footer.php $text .= "end"; echo $text thanks.
Advertisement
So, do you want to execute a file and have its results put into your $text variable, or do you want to have the contents of the file put into your variable without alteration?

If the former, look into the buffering features of PHP (ob_start(), etc.) -- you should be able to start buffering, execute the file via include(), then nab the contents of the buffer as a string; if the latter, try fopen()ing the file and just reading from it explicitly.

PHP manual on output control:
http://us4.php.net/manual/en/ref.outcontrol.php
fopen() did the trick! Thanks!
I have another question : I have a datetime in my database (mysql) and was wondering how to correctly enter a datetime into that via php. I just need to know the function as I already know how to connect to the database and add stuff to it. Just don't know how to get the time in php that will work with datetime in mysql...Thanks!
Nevermind.

date('Y-m-d H:i:s')

I actually used the previously mentioned site. Forgot it existed! heh

This topic is closed to new replies.

Advertisement