0

I'm trying to include some PHP script in with a HTML file, while I have found the command that achieves this, there seems to be an error in the way that I've layed out my code. I feel like I've missed a parentheses or something.

Here is a section of my HTML:

<title>Web Workers :: Home</title>
</head>
<body>

<?php
echo "<h1>Test</h1>";
include_once("htmlstatic.php");
?>

<nav id="navlist">
<ul>
<li class="links"> <a href="index.html">Home</a>                </li>
<li class="links"> <a href="topic1.html">Web Workers</a>        </li>
<li class="links"> <a href="register.html">Register</a>         </li>
<li class="links"> <a href="quiz.html">Quiz</a>                 </li>
<li class="links"> <a href="results.html">Results</a>           </li>
<li class="links"> <a href="about.html">About</a>               </li>
<li class="links"> <a href="enhancements.html">Enhancements</a> </li>
</ul>   
</nav>
<hr class="whitehr"/>
</body>
</html>

And here is my PHP:

<?php
echo "<h1>Web Workers</h1>";
echo "<hr class='whitehr'/>";
echo "<p>test</p>";
?>

Here is the output Output

Tauntaunwampa
  • 61
  • 1
  • 6

2 Answers2

3

Your file has .html extension that's why server cannot interpret the code starts with <?php

either tell server to interpret .html as .php or use .php file extension

for method first try below in .htaccess file

RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html
NullPoiиteя
  • 56,591
  • 22
  • 125
  • 143
Mert Metin
  • 411
  • 1
  • 8
  • 21
1

You cannot include a .php file in .html file, nor can you execute a php code in a .html file, rename your .html to .php to execute the php code. For your php code to be interpreted your files must have .php extension.

Edited:
As you did not mention in the question i am assuming that you are using the default php installation, with no setting to include PHP files in an HTML file.

Sourabh Kumar Sharma
  • 2,864
  • 3
  • 25
  • 33
  • 2
    ahem, not entirely true – Funk Forty Niner May 24 '15 at 04:04
  • like... Google Apache html as PHP – Funk Forty Niner May 24 '15 at 04:05
  • btw, that's not my downvote – Funk Forty Niner May 24 '15 at 04:06
  • @Fred-ii- though its true but its kind of mistake user is making (imo OP have no idea about it ) – NullPoiиteя May 24 '15 at 04:07
  • @Fred-ii-, yes that is correct but i am talking as per the OP requirements. – Sourabh Kumar Sharma May 24 '15 at 04:07
  • and I'm talking about your answer. You can run `.html` as PHP and you can include PHP into HTML and vice-versa. I've been doing it for years – Funk Forty Niner May 24 '15 at 04:08
  • @Sourabh even you can do it in htaccess like you can remove .php extension you can also rename .html it to .php – NullPoiиteя May 24 '15 at 04:08
  • Upvoted to counteract downvote. What he is saying is true. The user never dictated what version they were using of Apache and PHP so I'm assuming it's default installation. If you try to run php in an html file then it won't execute. – Morgan Green May 24 '15 at 04:09
  • I never said the answer was completely wrong @MorganGreen I said it's not entirely true. Plus, that wasn't my downvote, as I stated earlier. I've been dealing with using `.html` as PHP for years; I think I know what I'm talking about here. – Funk Forty Niner May 24 '15 at 04:11
  • @Fred-ii- I never said you didn't, but if the OP hadn't specified that they had modified anything to enable php in html, then I'm simply stating that it's extremely doubtful that they had or else you would think that they would have stated it. I also never said you were the cause of the downvote I just think the downvote was unmerited. – Morgan Green May 24 '15 at 04:13
  • http://stackoverflow.com/questions/4687208/using-htaccess-to-make-all-html-pages-to-run-as-php-files http://php.about.com/od/advancedphp/p/html_php.htm to name a few @Sourabh – Funk Forty Niner May 24 '15 at 04:14
  • @MorganGreen I always like giving a "not so entirely true" answer, the benefit of the doubt. ;-) – Funk Forty Niner May 24 '15 at 04:15
  • come on let it go ... @Fred-ii- i know you are telling right but most of newcomers have no idea about it, though its good to include relevant information ;) – NullPoiиteя May 24 '15 at 04:18
  • @Fred-ii-, you are right i am happy that you pointed out the additional thing , you spent your time for me thanks. – Sourabh Kumar Sharma May 24 '15 at 04:23
  • @NullPoiиteя yeah, I learned that lesson *real hard* myself years ago. Always nice to *share the wealth* ;-) – Funk Forty Niner May 24 '15 at 04:25