Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSharon Jeter
9,965 PointsWhen have .html file extension php will not run, change to .php file extension and html will not run
I have a web server installed using xampp on my hard drive. When I include any php code, i.e. <?php echo "text"; ?>, in my .html file, the php will not run. If I change the extension to .php, the php will run but the html will not run. Any suggestions in how I can get both to work?
3 Answers
Kevin Korte
28,149 PointsYou simply can't run any PHP in an html file.
You can run HTML in a php file. You can't run HTML inside of a PHP block in a PHP file.
What does the contents of this file look like exactly?
Kevin Korte
28,149 PointsYou can't run php in a file that has a html extension.
<?
is a shortcut, that as I understand it is not fully supported by some versions of php. Try using <?php
sometimes when php errors it won't do anything but return a white blank page.
But you do have to resave this file with that php extension.
Sharon Jeter
9,965 PointsHere's an example, The file is named index.html and the php in the title does not execute.
<html> <head> <title><? echo "PC Tutor";?></title> <link rel="stylesheet" href="css/style.css" type="text/css"> <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Oswald:400,700" type="text/css"> <link rel="shortcut icon" href="favicon.ico"> </head> <body>
<ul>
<li>Shirts</li>
<li>Contact</li>
<li>Shopping Cart</li>
</ul>
</body> </html>