I have the following script:
<?php print "1st line\n"; print "2nd line\n"; ?>
The lines are all printed in one line. What is the reason for this?
your browser expects html, so provide it with html.
<br> comes to mind
So if I ran it from a shell it would the script would be fine?
david8787;10942593 wrote:So if I ran it from a shell it would the script would be fine?
yes \n would be fine for shell or writing to a text file.
You can also view the source code in your browser and you should see it printed on a new line. Another option would be to tell the browser that it's not HTML but plain text by using a header:
header('Content-Type: text/plain');
Thanks for the clarification and the header tip.
or
<?php echo '<pre>'; print "1st line\n"; print "2nd line\n"; echo '</pre>'; ?>
pre = Preformatted text