What potential pitfalls should PHP beginners be aware of when trying to extract data from text files for display on a website?

One potential pitfall for PHP beginners when extracting data from text files for display on a website is not properly handling file paths and permissions. Make sure to specify the correct file path and ensure that the PHP script has the necessary permissions to read the file.

$file_path = 'data.txt';

if (file_exists($file_path) && is_readable($file_path)) {
    $data = file_get_contents($file_path);
    echo $data;
} else {
    echo 'Error: Unable to read file.';
}