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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux