Re: [PHP] no newline after "?>" in the resulting HTML
On Tue, 21 Mar 2006 10:38:47 +0200 [EMAIL PROTECTED] (Andrei) wrote: > Really I think it would be loosing time documenting that you can put a > new line after ?>! > I mean it's obvious that what's outside php tags will be printed rite? > > Andy You can put anything after "?>" but if you put a newline, that newline is then deleted from the resulting HTML. If you put a space and a newline after that space, both will not be deleted. That is all. P.S. could you not top-post, please. > Rostislav Krasny wrote: > > On Mon, 20 Mar 2006 17:51:32 -0600 (CST) > > [EMAIL PROTECTED] ("Richard Lynch") wrote: > > > >> On Sat, March 18, 2006 12:36 pm, Rostislav Krasny wrote: > >>> Hello World > >>> > >>> Hello World > >>> Why there is no newline afer " Hello World" ? > >>> Is it a PHP bug or the tutorial should be updated? > >> The tutorial is imprecise, and glosses over this detail. > >> > >> For very good reasons, ?>[newline] ignores the trailing [newline] > >> character. > >> > >> If you want the newline, you should do: > >> > >> >> echo "Hello World\n"; > >> ?> > > > > Thanks for replying. You're suggesting an obvious but not so handy > > workaround of this feature. Jim Lucas, in his reply, pointed me out to > > much easier one. He suggested just to add a space after the "?>". I'm > > wondering why this trivial thing isn't known to all and wasn't well > > documented. > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] no newline after "?>" in the resulting HTML
Really I think it would be loosing time documenting that you can put a new line after ?>! I mean it's obvious that what's outside php tags will be printed rite? Andy Rostislav Krasny wrote: On Mon, 20 Mar 2006 17:51:32 -0600 (CST) [EMAIL PROTECTED] ("Richard Lynch") wrote: On Sat, March 18, 2006 12:36 pm, Rostislav Krasny wrote: Hello World Hello World Why there is no newline afer " Hello World" ? Is it a PHP bug or the tutorial should be updated? The tutorial is imprecise, and glosses over this detail. For very good reasons, ?>[newline] ignores the trailing [newline] character. If you want the newline, you should do: Hello World\n"; ?> Thanks for replying. You're suggesting an obvious but not so handy workaround of this feature. Jim Lucas, in his reply, pointed me out to much easier one. He suggested just to add a space after the "?>". I'm wondering why this trivial thing isn't known to all and wasn't well documented. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] no newline after "?>" in the resulting HTML
On Mon, 20 Mar 2006 17:51:32 -0600 (CST) [EMAIL PROTECTED] ("Richard Lynch") wrote: > On Sat, March 18, 2006 12:36 pm, Rostislav Krasny wrote: > > Hello World > > > > > Hello World > > > Why there is no newline afer " Hello World" ? > > Is it a PHP bug or the tutorial should be updated? > > The tutorial is imprecise, and glosses over this detail. > > For very good reasons, ?>[newline] ignores the trailing [newline] > character. > > If you want the newline, you should do: > >echo "Hello World\n"; > ?> Thanks for replying. You're suggesting an obvious but not so handy workaround of this feature. Jim Lucas, in his reply, pointed me out to much easier one. He suggested just to add a space after the "?>". I'm wondering why this trivial thing isn't known to all and wasn't well documented. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] no newline after "?>" in the resulting HTML
On Sat, March 18, 2006 1:23 pm, Adrian wrote: > Is there a way to circumvent this? > My template engine compiles templates to PHP files and this "feature" > makes the output html code look awful sometimes. You could: 1. Add \n after all the lines of output where it matters. 2. Use TWO newlines after ?> tags newline I *believe* this will output: Test newline PHP only "eats" *ONE* newline after ?>, not multiple newlines, almost-for-sure. -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] no newline after "?>" in the resulting HTML
On Sat, March 18, 2006 12:36 pm, Rostislav Krasny wrote: > Hello World > > Hello World > Why there is no newline afer " Hello World" ? > Is it a PHP bug or the tutorial should be updated? The tutorial is imprecise, and glosses over this detail. For very good reasons, ?>[newline] ignores the trailing [newline] character. If you want the newline, you should do: Hello World\n"; ?> As for WHY the [newline] after ?> is ignored, it just turns out that there are more times when you want it that way than the other, *AND* it's trivial to insert a \n into your output, *AND* it would be very hard to come up with a way to make the newline NOT appear if the default was to have it appear, *AND* a *TON* of things would go wrong if the extra newline appeared where you don't want it, but it's pretty unimportant if a newline is missing at that point in the tutorial and in most real-world cases (IE, HTML output) where you have ?>[newline] It's not a bug ; It's a feature -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] no newline after "?>" in the resulting HTML
Rostislav Krasny wrote: On Sat, 18 Mar 2006 13:49:19 -0800 [EMAIL PROTECTED] (Jim Lucas) wrote: put a space after the ?> and you will retain the line feed It also adds that space before the retained line feed, but so it looks better anyway. Excellent suggestion, thank you! Could it be added to the FAQ and to the official PHP tutorial? At least to the discussed part of the tutorial, so PHP beginners like me wouldn't be confused :-) I added it to the tutorial. It will show up the next time the manual is built. -Rasmus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] no newline after "?>" in the resulting HTML
On Sat, 18 Mar 2006 13:49:19 -0800 [EMAIL PROTECTED] (Jim Lucas) wrote: > put a space after the ?> and you will retain the line feed It also adds that space before the retained line feed, but so it looks better anyway. Excellent suggestion, thank you! Could it be added to the FAQ and to the official PHP tutorial? At least to the discussed part of the tutorial, so PHP beginners like me wouldn't be confused :-) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] no newline after "?>" in the resulting HTML
Rostislav Krasny wrote: Hi, I've tried to ask the following question on internals@lists.php.net but has been pointed out that that mailing list isn't appropriate. So I'm resinding it here. I am a newbie to PHP. I've installed a php5-cgi-5.1.2_1 from FreeBSD ports collection and access it by FastCGI protocol from nginx HTTP server. I've tried an example of "Hello World" PHP script from the following tutorial page: http://www.php.net/manual/en/tutorial.firstpage.php This is how the resulting HTML code is expected to look like, according to the tutorial: PHP Test Hello World And following is the HTML code I've got: PHP Test Hello World Why there is no newline afer " Hello World" ? Is it a PHP bug or the tutorial should be updated? P.S. I'm not subscribed to this list, please Cc your reply. put a space after the ?> and you will retain the line feed jim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] no newline after "?>" in the resulting HTML
Rostislav Krasny wrote: Why there is no newline afer "Hello World"? Is it a PHP bug or the tutorial should be updated? I discuss this here: http://shiflett.org/archive/151 It's a feature of PHP that has some advantages and disadvantages, and it's not likely to change (consistency has merit, regardless of what you think of the behavior). Hope that helps. Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] no newline after "?>" in the resulting HTML
Adrian wrote: Is there a way to circumvent this? My template engine compiles templates to PHP files and this "feature" makes the output html code look awful sometimes. Nope. Put in an extra newline after ?> if you need them, or put a \n at the end of the last echo inside the PHP block. -Rasmus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] no newline after "?>" in the resulting HTML
Is there a way to circumvent this? My template engine compiles templates to PHP files and this "feature" makes the output html code look awful sometimes. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] no newline after "?>" in the resulting HTML
Brady Mitchell wrote: Why there is no newline afer " Hello World" ? Is it a PHP bug or the tutorial should be updated? The tutorial is fine. The sample code mentioned: PHP Test Hello World'; ?> Contains a line break after the Hello World 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: ... And have that opening tag be on the first line of the file. Another reason is for include files. If you include a file that ends with ?> 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
RE: [PHP] no newline after "?>" in the resulting HTML
> Why there is no newline afer " Hello World" ? > Is it a PHP bug or the tutorial should be updated? The tutorial is fine. The sample code mentioned: PHP Test Hello World'; ?> Contains a line break after the Hello World is echoed . Check your code, if you don't have that line break, PHP is not going to create it for you. Brady -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] no newline after "?>" in the resulting HTML
Hi, I've tried to ask the following question on internals@lists.php.net but has been pointed out that that mailing list isn't appropriate. So I'm resinding it here. I am a newbie to PHP. I've installed a php5-cgi-5.1.2_1 from FreeBSD ports collection and access it by FastCGI protocol from nginx HTTP server. I've tried an example of "Hello World" PHP script from the following tutorial page: http://www.php.net/manual/en/tutorial.firstpage.php This is how the resulting HTML code is expected to look like, according to the tutorial: PHP Test Hello World And following is the HTML code I've got: PHP Test Hello World Why there is no newline afer " Hello World" ? Is it a PHP bug or the tutorial should be updated? P.S. I'm not subscribed to this list, please Cc your reply. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php