Jump to content

Includes Question =-= Solved


ravenshade

Recommended Posts

I am delving into PHP, and I'm getting to the stage where I'm going to need includes and I was wondering how they worked. For instance, can you use them to include HTML and have it display exactly? i.e I have a div tag, and if I put it into its own file, could I include that file and then have it display just as it does now? Secondly, does it have to be a specific file type, for instance, php files or html files? Thanks in advance. :)

Link to comment
Share on other sites

For instance, can you use them to include HTML and have it display exactly? i.e I have a div tag, and if I put it into its own file, could I include that file and then have it display just as it does now?
Yes. Anything outside out <?php ?> blocks will be passed on literally.
Secondly, does it have to be a specific file type, for instance, php files or html files?
By default, they have to end in .php (but the MIME type is still text/html).
Link to comment
Share on other sites

Includes can be named as any type of file, but the content of the file is always assumed to be html code unless you set another token inside the included file to (for example) use php.Example:include 'file.php';include 'file.inc';include 'file.inc.php';will all be successful. The contents of the file will be parsed as html, so if you need some php code parsed inside the included file, use php tokens as follows:

<div>stuff</div><?phpecho 'stuff from included file';?><div>stuff</div>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...