What is the difference between fread() and file_get_contents() in PHP?

The main difference between `fread()` and `file_get_contents()` in PHP is how they read files. `fread()` reads a specified number of bytes from a file pointer, while `file_get_contents()` reads the entire file into a string. If you need to read a file in chunks or control the number of bytes read, use `fread()`. If you simply need to read the entire contents of a file into a string, use `file_get_contents()`.

// Using fread() to read a file in chunks
$handle = fopen("example.txt", "r");
if ($handle) {
    while (($chunk = fread($handle, 1024)) !== false) {
        // Process the chunk
    }
    fclose($handle);
}

// Using file_get_contents() to read the entire file into a string
$content = file_get_contents("example.txt");