What is the difference between including PHP code in an HTML file versus a PHP file?

When including PHP code in an HTML file, the PHP code will not be executed unless the server recognizes the file as a PHP file. To ensure that PHP code is executed, it is recommended to include the PHP code in a file with a .php extension. This way, the server will interpret and execute the PHP code correctly.

// Example of including PHP code in an HTML file
// Incorrect way (in an HTML file):
<html>
<body>
<?php echo "Hello, World!"; ?>
</body>
</html>

// Correct way (in a PHP file):
// index.php
<?php
echo "Hello, World!";
?>