php try file new SplFileObject file txt while file- eof echo file- fge

1
2
3
4
5
6
7
8
9
<?php
try {
$file = new SplFileObject("file.txt", 'r');
while (!$file->eof()) {
echo $file->fgets(), '<br>';
}
}catch(RuntimeException $e) {
echo $e->__tostring();
}