PHP块未在html中解析

I am writing the following html code:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 

<script type="text/javascript">
    function detectBrowser(){
        if(navigator.appName === "Microsoft Internet Explorer"){
            window.open("redirect.html", "_parent");
        }
    }
</script>
</head>

<body onload="detectBrowser()">
<div class="mainBody">  
<?php
    echo "test";
?>
</div>
</body>
</html>

But the php block doesn't display test for me. It looks like it is not parsed and I can see the php code in the webpage's source. Any one can tell the problem?
Thank you

You can enable parsing of PHP in files with .html extensions in your httpd.conf file.

Look for a line like this and make sure .html is an option.

 AddType application/x-httpd-php .php .php3 .phtml .html 

You could probably add it to an .htaccess file in the docroot of you site as well, but I've not tried this personally.

You could change this in your .htaccess file. (if it doesn't exist just create the file (text only) in the same folder as your file)

AddType application/x-httpd-php .html

However this would make all static files also go through the PHP parser which is unnecessary.

I would suggest the best solution is to rename the file instead with extension .php. Then in your .htaccess file you could rewrite just this address, then you will be able to access it with the .html extension anyway.

RewriteEngine on
RewriteRule ^myfile.html$ myfile.php