What potential issues can arise when reading the last character from a text file in PHP?

When reading the last character from a text file in PHP, one potential issue that can arise is reading an extra newline character at the end of the file. This can lead to unexpected behavior in your script, especially if you are processing the data character by character. To solve this issue, you can use the `rtrim()` function to remove any trailing whitespace characters, including newline characters, from the last character read from the file.

$file = 'example.txt';
$handle = fopen($file, 'r');
$lastChar = '';
if ($handle) {
    while (($char = fgetc($handle)) !== false) {
        $lastChar = $char;
    }
    fclose($handle);
    $lastChar = rtrim($lastChar);
    echo "Last character in the file: $lastChar";
} else {
    echo "Error opening the file.";
}