Jump to content

Includes Question =-= Solved


ravenshade
 Share

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. :)

Edited by ravenshade
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). Edited by Synook
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>

Edited by jlhaslip
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...