I tried using the '' or ' ' empty strings in PHP but it seems to have been trimmed when using the echo statement for displaying it in the browser.
echo ' the quick brown fox jumps over the lazy dog.';
The statement above is been stripped of the white/blank spaces.
How can I do this in PHP? How can I print blank lines without them being stripped out?
PHP isn't stripping anything; your browser is ignoring the space. Right-click, View Source and you'll see what I mean. Either wrap the whole string in a <pre>
tag, or use a non-breaking space, e.g.,
, for each piece of whitespace you want to leave. (Or use style='white-space: pre;'
on the element.)
echo ' the quick brown fox jumps over the lazy dog.';
Or:
echo '<pre> the quick brown fox jumps over the lazy dog.</pre>';
Or:
echo '<p style="white-space: pre;"> the quick brown fox jumps over the lazy dog.</p>';
Or (@SecondRekudo):
Or send a Content-type: text/plain header.
Which would look like:
header('Content-type: text/plain');
Which needs to be called before any output to the browser (or you'll get a warning and the header won't be sent).