0

https://i.sstatic.net/L9SYq.jpg

I have an HTML page with embedded PHP:

<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />  
<title>HTML with embedded PHP</title>
</head>

<body>
This is normal HTML code
<?php echo " Scooby Doo "; ?>
Back into normal HTML
</body>
</html>

results in the php code being commented out when viewed on the testing server:

<!--?php echo "Scooby Doo"; ?-->

The server is localhost and running a fresh install of WAMP. Has anyone any ideas as to how to get my php code to parse correctly in the HTML?

Tried it in IE but same results. Tried it on another server XAMPP and got the same. Running Windows 10. Is it an application permissions thing with apache? PHP runs fine - have made a php page calling <?php phpinfo(); ?> and it works. I'm stumped. Thanks.

2
  • rename your file as .php extension Commented Sep 29, 2015 at 16:49
  • 1
    A single PHP snippet in your page demands that page to have .php extention. Commented Sep 29, 2015 at 16:49

1 Answer 1

1

Simply you can't do it. Your HTML page cannot be interpreted as PHP script by the apache web server, because it doesn't recognize as a valid PHP extension. Try add this line to your .htaccess file

AddType application/x-httpd-php .htm .html

This simple line will tell your apache web server to handle also .html as PHP script.

But however, you should rename your file using .php extension and you solved the problem

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Diego - adding that handler has fixed it. I have to stick with HTML unfortunately but that solution works perfectly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.