What are the differences between using fopen/fread and file functions to read a file in PHP?

When reading a file in PHP, using the fopen and fread functions allows for more control and flexibility in handling the file, such as reading specific portions or reading binary data. On the other hand, using file functions like file_get_contents or file simply reads the entire file into memory, which may be more convenient for simple file reading tasks but less efficient for large files.

// Using fopen/fread to read a file
$filename = "example.txt";
$handle = fopen($filename, "r");
if ($handle) {
    while (($line = fgets($handle)) !== false) {
        echo $line;
    }
    fclose($handle);
}

// Using file functions to read a file
$filename = "example.txt";
$file_contents = file_get_contents($filename);
echo $file_contents;