Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:100428 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 97305 invoked from network); 7 Sep 2017 01:45:10 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Sep 2017 01:45:10 -0000 X-Host-Fingerprint: 95.148.70.109 unknown Received: from [95.148.70.109] ([95.148.70.109:20209] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8C/6B-10715-4A4A0B95 for ; Wed, 06 Sep 2017 21:45:09 -0400 Message-ID: <8C.6B.10715.4A4A0B95@pb1.pair.com> To: internals@lists.php.net X-Mozilla-News-Host: news://news.php.net:119 Date: Thu, 7 Sep 2017 02:45:05 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:49.0) Gecko/20100101 Firefox/49.0 SeaMonkey/2.46 MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 95.148.70.109 Subject: Consider only ignoring newlines for final ?> in a file From: ajf@ajf.me (Andrea Faulds) 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:
foo bar
May instead end up looking something like:
foo bar
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! -- Andrea Faulds https://ajf.me/