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

The main difference between readfile() and file_get_contents() in PHP is that readfile() outputs the file directly to the browser while file_get_contents() returns the file contents as a string. If you want to output the file directly to the browser, you should use readfile(). However, if you need the file contents as a string for further processing, file_get_contents() is the appropriate choice.

// Using readfile() to output the file directly to the browser
$file = 'example.txt';
readfile($file);
```

```php
// Using file_get_contents() to get the file contents as a string
$file = 'example.txt';
$file_contents = file_get_contents($file);
echo $file_contents;