When you are using PHP to make a web app, there are a few layers involved:
- Your PHP code, which outputs some data to
- a web server, which transmits the data over the network to
- a web browser, which parses the data and displays it on the screen.
Note that in the above, it is just data that is being passed along. In your case, that data is HTML, but it could just as easily be plain text or even a PNG formatted image. (This is one reason why you send a Content-Type:
header, to specify the format of your data.)
Because it is so often used for HTML, PHP has a lot of HTML-specific features, but that's not the only format it can output. So, while a newline character is not always useful for HTML, is is useful:
- if you want to format the HTML you are generating, not for the web browser, but for another person to be able to read;
- if you want to generate plain text or another format where newline characters do matter.