How can the feof function be correctly implemented in the PHP script to avoid errors?

When using the `feof` function in PHP to check for the end of a file, it is important to make sure that you are using it correctly within a loop that reads the file line by line. This ensures that the function is called after each line is read and prevents errors such as infinite loops. Additionally, make sure to open the file using the `fopen` function before using `feof` and close the file using `fclose` after reading it.

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

if ($file) {
    while (!feof($file)) {
        $line = fgets($file);
        // Process the line here
    }
    fclose($file);
} else {
    echo "Error opening file.";
}