How can the context switch to HTML affect the display of variables in PHP?

When switching context to HTML in PHP, variables need to be properly echoed within the HTML code to be displayed correctly. This can be achieved by enclosing the variable within PHP tags and using the echo statement. Failure to do so may result in the variable being displayed as plain text instead of its value.

<?php
$variable = "Hello, World!";
?>
<!DOCTYPE html>
<html>
<head>
    <title>Display Variable in HTML</title>
</head>
<body>
    <p><?php echo $variable; ?></p>
</body>
</html>