How can PHP beginners effectively store HTML code from an external file in a variable?

To store HTML code from an external file in a variable in PHP, beginners can use the file_get_contents() function to read the contents of the external file and then store it in a variable. This allows for easy manipulation and output of the HTML code within the PHP script.

<?php
// Read the contents of the external HTML file into a variable
$html = file_get_contents('external_file.html');

// Output the HTML code stored in the variable
echo $html;
?>