What are the potential pitfalls of using file_get_contents() function in PHP to read a file and display its content?

One potential pitfall of using the file_get_contents() function in PHP is that it reads the entire file into memory, which can be inefficient for large files and may cause memory issues. To solve this issue, it is recommended to use the fopen() function with fread() to read the file in chunks instead of all at once.

$file = 'example.txt';
$handle = fopen($file, 'r');

if ($handle) {
    while (!feof($handle)) {
        $chunk = fread($handle, 1024);
        echo $chunk;
    }

    fclose($handle);
} else {
    echo 'Error opening file.';
}