On Thu, Sep 7, 2017 at 3:45 AM, Andrea Faulds <a...@ajf.me> wrote: > Hi everyone, > > This is the tiniest of issues, but it's bugged me for a long time and > makes the HTML produced by PHP code less readable than it out to be. > Specifically, PHP ignores a newline immediately following a ?> tag. The > reason for this is, from what I recall, to prevent issues where whitespace > at the end of a PHP file is echoed before headers can be sent. On UNIX in > particular, all text files (should) end in a newline, so this is a > reasonable and necessary feature. > > However, for ?> tags anywhere that aren't right at the end of the file, > this is just a nuisance that makes for messy output. For example, HTML > output that should look like: > > <table> > <tr> > <td>foo</td> > <td>bar</td> > </tr> > </table> > > May instead end up looking something like: > > <table> <tr> > <td>foo</td> <td>bar</td> > </tr></table> > > Of course, HTML doesn't matter so much, it'll render the same to the > end-user. However, for outputting e.g. plain text, newlines can be > significant, and so you have to insert an ugly and surprising extra newline > following a tag. > > Would anyone object to me changing how PHP handles this so that only the > final ?> tag consumes its following newline, and only at the end of the > file? > > Thanks! >
It also goes the other way. Whether you want to drop the newline after ?> depends (roughly) on whether the code is control flow (drop) or trailing output (don't drop). If the newline is not dropped anymore it doesn't mean that the output will look nice, it's just going to be broken in a different way. Nikita