What potential issues or errors could arise when trying to read a text file in PHP?

One potential issue when trying to read a text file in PHP is not handling file permissions correctly. If the file does not have the appropriate read permissions, PHP will not be able to read the file contents. To solve this issue, you can check and set the file permissions before attempting to read the file.

// Check file permissions before reading
if (is_readable('example.txt')) {
    // Open the file for reading
    $file = fopen('example.txt', 'r');

    // Read the file contents
    $contents = fread($file, filesize('example.txt'));

    // Close the file
    fclose($file);

    // Output the file contents
    echo $contents;
} else {
    echo 'File is not readable.';
}