Also note that if you want PHP in your included()'d file, you have to put <? and ?> around the PHP. When you include() a file, PHP starts off reading it in HTML mode.
Include() just takes the included file and sticks it into the original file. The variable scope in an included file is the same as the spot where the include() was called. You really only want to call <html> once in your script. So if it's in an include()'d file, that's fine. If you calling an included()'d file from the middle of your script, the include()'d file doesn't have to have <html>, etc...just valid code. Take this example. You can use an include file to format a row for a table. ##include.php## <tr><td align="center" bgcolor="blue">$data</td></tr> ##main.php## <table border="1"> <? for($data=0;$data<100;$data++) { include("include.php"); } ?> </table> That'll make 100 table rows for you. Include files are good for function declarations and separating pieces of your HTML apart to easily manage it. ---John Holmes... > -----Original Message----- > From: Kevin Stone [mailto:[EMAIL PROTECTED]] > Sent: Saturday, May 25, 2002 8:54 PM > To: [EMAIL PROTECTED] > Subject: Re: [PHP] Include (Newbie question) > > No, not exactly. The idea behind the include() function in PHP is to > append > and execute code to the currently running script. This is great for > organizing your code into more easier to manage chunks. PHP will attempt > to > parse and execute the included file as a PHP file regardless of the file > extension. So you can do this for example... > > -- myhtml.html -- > <div align="center">Hello <?echo $var;?></div> > ------------------ > > -- myphp.php -- > $var = "World"; > <?include("myhtml.html")?> > ----------------- > > This will print out "Hello World". So that answers two questions with one > stone (err.. yah). include() is a function not a method. And you don't > need the <html> tag to display included html. The browser will > automatically assume an html header upon any textual output unless > otherwise > specified. > > Check out the manual for more information. > http://www.php.net/manual/en/function.include.php > > Hope this helps > -Kevin > > ----- Original Message ----- > From: "r" < > > To: <[EMAIL PROTECTED]> > Sent: Sunday, May 26, 2002 5:11 AM > Subject: [PHP] Include (Newbie question) > > > > Hey, > > I have just being going through the manual (windows version) and am a > bit > > confused about "include", > > If I want the scope to affect the whole page I do this right: > > > > (example page) > > <html> > > <body> > > <?php > > include blah.php > > ?> > > some html > > <?php > > use some functions to call blah.php > > ?> > > is this correct? > > > > and my second question is if I am including a html file will that file > need > > to have a <html><head><body> etc etc > > or you must have the <html><head>etc only in one file? > > > > Since am confused about this and it comes straight from the RTFM() > > function.....any help appreciated. :-) > > > > Cheers, > > -Ryan. > > > > > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php