How can PHP be used to automatically add " " after each line of text when reading from a .txt file?

To automatically add " " after each line of text when reading from a .txt file in PHP, you can read the file line by line using functions like `fgets()` or `file()` and then append " " at the end of each line before displaying or processing the content. This will ensure that there is a non-breaking space added after each line, maintaining the formatting when displayed on a webpage.

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

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