What are the advantages and disadvantages of using fread to read files before applying preg_replace in PHP?

When using `fread` to read files before applying `preg_replace` in PHP, the advantage is that you can read the file contents into memory efficiently. However, a disadvantage is that if the file is too large, it may consume a lot of memory. To solve this issue, you can read the file line by line using `fgets` instead of reading the entire file at once.

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

while (!feof($file)) {
    $line = fgets($file);
    $output .= preg_replace('/pattern/', 'replacement', $line);
}

fclose($file);
echo $output;