Question about include
Posted: Sun Jul 26, 2009 10:45 am
Does include effectively put ?>...<?php tags before and after?
I was trying to include a file containing only a static array definition (let's say, the names of the months), but the file contents were being displayed when the script was run and not incorporated in the script. After a fair amount of trial-and-error, I tried enclosing the file contents in <?php...?> tags, and that did the trick.
This would make some sense: as I understand it, include is often (most often?) used to insert html boilerplate, but I don't believe I've seen this made clear.
While I'm on the subject, there are a couple of other things I'd like to clarify about includes.
Does it matter what the extension of the included file is?
As I understand it, includes are parsed and expanded statically, at load time. So you can't do something like "$filename=$basename . '01'; include $filename;" or " if A include fileA;". Do I have that right?
Thanks for your help.
I was trying to include a file containing only a static array definition (let's say, the names of the months), but the file contents were being displayed when the script was run and not incorporated in the script. After a fair amount of trial-and-error, I tried enclosing the file contents in <?php...?> tags, and that did the trick.
This would make some sense: as I understand it, include is often (most often?) used to insert html boilerplate, but I don't believe I've seen this made clear.
While I'm on the subject, there are a couple of other things I'd like to clarify about includes.
Does it matter what the extension of the included file is?
As I understand it, includes are parsed and expanded statically, at load time. So you can't do something like "$filename=$basename . '01'; include $filename;" or " if A include fileA;". Do I have that right?
Thanks for your help.