How can file_get_contents be used in PHP to read the contents of a .txt file for insertion into a webpage?

To read the contents of a .txt file in PHP and insert it into a webpage, you can use the file_get_contents function to retrieve the text from the file and then echo it within the HTML code of the webpage.

<?php
$file = 'example.txt';
$text = file_get_contents($file);
echo "<div>{$text}</div>";
?>