I am reading log files that have been compressed with gzip in a php script. Nothing is missing from the text, but all of the instances of multiple spaces have been reduced to a single space.
Here is an example of the output:
+-----------------------------------------------------------------------------+
| Exit Status : 1 |
When it should have looked like this:
+-----------------------------------------------------------------------------+
| Exit Status : 1 |
Here is the relevant part of the script I think:
$lines = gzfile("$filename.gz");
# If the file is empty, say that to be more user friendly
if($lines == "") {
echo "File empty";
} else {
echo "<div style=\"font-family:courier new;font-size:12pt\">";
foreach ($lines as $line) {
echo nl2br($line);
}
echo "</div>";
}
I also tried it without nl2br, just as a test, and the spaces were still reduced to one. The file is intact as I viewed it with zcat in a terminal just to be sure something hadn’t actually written the file incorrectly. Any ideas?
Since you’re outputing HTML markup, I presume you’re viewing the output of your PHP script in a web browser. If this is the case, you’re encouring a quirk of HTML, not PHP. Specifically, web browsers render any expanse of whitespace as one space. It’s how HTML works.
To view all the spaces, you need to wrap the output in
<pre></pre>tags.