What is the importance of using the correct file extension (.php) when trying to display PHP variables in an HTML page?

Using the correct file extension (.php) is important because it tells the server to interpret the file as containing PHP code. Without the .php extension, the server will not process the PHP variables and they will not be displayed correctly in the HTML page.

<?php
$variable = "Hello, World!";
?>

<!DOCTYPE html>
<html>
<head>
    <title>PHP Variable Example</title>
</head>
<body>
    <h1><?php echo $variable; ?></h1>
</body>
</html>