Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
Jenny Swift21,999 Points
Can HTML files be included with PHP?
Hi, I'm new to PHP. Is it possible to include HTML files with PHP, for example like this: <?php include('includes/menu.html'); ?>
I saw something like this at css-tricks.com, but I haven't yet got it to work, whereas if I change my file extensions from .html to .php things work fine.
If it is not possible to include html files with php, I'm guessing that means if I had a website with a navigation bar that I wanted on all my pages I would then need to change every one of my html files to php files? Are there any drawbacks to doing this please?
Here's a link to the php include documentation, there you can read all about php include: http://www.php.net/manual/en/function.include.php
As for CSS-tricks, it could be a misprint or copy-paste error, it happens :)
You can have HTML in a .php file, so changing the fileextention of your html-file to .php is a good option. It doesn't have to have any php in it. In fact in most php projects the html files usually have the file extension .php even though they contain mostly HTML.
I don't think it's possible to do a <?php include('includes/menu.html'); ?>
Jenny Swift21,999 Points
So if it isn't possible to include an html file that has an html extension, can anyone please explain why http://css-tricks.com/including-navigation-code-on-all-pages-even-with-current-navigation-highlighting/
says this: "The classic menu HTML which you can transform into any number of beautiful things through CSS. You could include that in all your pages by putting it into it's own HTML file (like "menu.html") and including it on your pages with some kind of simple include statement like this PHP snippet:
<?php include_once("menu.html"); ?>"