ravenshade Posted September 12, 2009 Report Share Posted September 12, 2009 (edited) 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 September 13, 2009 by ravenshade Link to comment Share on other sites More sharing options...
Synook Posted September 12, 2009 Report Share Posted September 12, 2009 (edited) 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 September 12, 2009 by Synook Link to comment Share on other sites More sharing options...
jlhaslip Posted September 12, 2009 Report Share Posted September 12, 2009 (edited) 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 September 12, 2009 by jlhaslip Link to comment Share on other sites More sharing options...
ravenshade Posted September 13, 2009 Author Report Share Posted September 13, 2009 Problem solved Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now