Re: no newline after "?>" in the resulting HTML

From: Date: Sat, 18 Mar 2006 19:13:58 +0000
Subject: Re: no newline after "?>" in the resulting HTML
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-232190@lists.php.net to get a copy of this message
Brady Mitchell wrote:
Why there is no newline afer " <p>Hello World</p>" ? Is it a PHP bug or the tutorial should be updated?
The tutorial is fine. The sample code mentioned: <html> <head> <title>PHP Test</title> </head> <body> <?php echo '<p>Hello World</p>'; ?> </body> </html> Contains a line break after the <p>Hello World</p> is echoed . Check your code, if you don't have that line break, PHP is not going to create it for you.
That's actually not true. A line break after a closing ?> is ignored. This is to make it possible to have something like this: <?php /* do something */ ?> <html> ... </html> And have that opening <html> tag be on the first line of the file. Another reason is for include files. If you include a file that ends with ?><newline> then you normally don't want that newline. Having a newline output for each file you include doesn't make much sense. So yes, technically the tutorial is wrong. -Rasmus

« previous php.general (#232190) next »