php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #13954 newline is stripped after the closing ?>
Submitted: 2001-11-06 10:37 UTC Modified: 2001-11-06 15:10 UTC
From: aln00 at udcast dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 4.0.6 OS: linux 2.2.19
Private report: No CVE-ID: None
 [2001-11-06 10:37 UTC] aln00 at udcast dot com
Hello,

I'm using php as a powerful generic macro processor for ascii files, which contains some php code. Everything is OK, except a very annoying problem when the php code generates nothing. For example:

--------- FILE 1 ---------
var0 = "a constant string"
var1 = <?= $hh1 ?>
var2 = <?= $hh2 ?>
var3 = "another constant string"
---------------------------

with $hh1 and $hh2 empty will generate:

---------------------------
var0 = "a constant string"
var1 = var2 = var3 = "another constant string"
---------------------------

instead of :
---------------------------
var0 = "a constant string"
var1 = 
var2 = 
var3 = "another constant string"
---------------------------

NB: If I put a space after the ?>, the newline is not stripped.



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-11-06 15:10 UTC] jeroen@php.net
This is documented behaviour, and with a reason (to allow better formatting of php code without ruining the layout of the output)

RTFM: http://uk.php.net/manual/en/language.basic-syntax.php#language.basic-syntax.phpmode

(admittingly, it's just a very small sentence...)
 [2003-01-25 17:23 UTC] hz11 at nyu dot edu
I'd like another look at this issue, since the documentation seems to clash with actual behavior.

Using a CLI compiled 4.3.0 binary, this script:

#!/bin/psh
<?php

$foo = 'Hello';
$bar = 'World';

?>

<?=$foo?>
<?=$bar?>

<?php

echo 'DONE!';

?>


This script will produce:

<empty line>
HelloWorld
DONE![unix prompt]$

Note that there is no trailing space (x20) after <?=$foo?> and <?=$bar?>  -  only a newline (x0A)

According to http://www.php.net/manual/en/language.basic-syntax.php#language.basic-syntax.phpmode

"The closing tag for the block will include the immediately trailing newline if one is present."

Now if I add a x20 after the closing tag, then the newlines is honored.  Why does this behavior make any sense?  Especially since the aforementioned URL has statements like "...because when PHP hits the ?> closing tags, it simply starts outputting whatever it finds until it hits another opening tag" throughout.  Obviously, however, this isn't true, since PHP decides to ignore the newline immediately after the closing tag.

I don't understand why this behavior would be desired anyway; what is outside the PHP tags should simply be passed through.  And especially since the docs are misleading about this.

Thank you,

Hans
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Wed Jul 06 10:03:41 2022 UTC