Group: http://groups.google.com/group/intro2php-matt-2011-01/topics
- Question about embedded newlines [2 Updates]
kristin robinson <kayk...@gmail.com> Feb 05 04:29PM -0800 ^
So Evolve and I were looking at code samples taken from the php online
manual. Here is one example
echo 'You can also have embedded newlines in
strings this way as it is
okay to do';
(from page: http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.single)
We were surprised when looking at involve's code exercise (http://
codepad.org/udcdHD39) that the Le Guin poem wouldn't render in the
browser with the embedded newlines. It just runs all together unless
breaks or returns are manually added. This holds true for single,
double, heredoc syntax and nowdoc syntax. So where are the embedded
newlines?
I looked at the source code and the source code had preserved the
newlines. But since there was no HTML or other instruction to tell
the browser to preserve the formatting, the newlines are only
preserved in the source code the PHP is creating.
Matt: is this understanding correct?
Matt Buscemi <ikim...@gmail.com> Feb 05 03:18PM -1000 ^
Kristin,
Yes, this is correct. PHP will output any newlines that you write into a
string, even if you actually hit return and continue typing on the next
line. Codepad will even show you the newlines in the output, as in the
example of your Ursula Le Guin quote. However, the HTML produced by running
the PHP file is ultimately subjected to the browser, which will ignore
newlines and only place them where it finds the <br/> tag, or after block
elements.
Hope this helps!
- Matt