Jump to content
Larry Ullman's Book Forums

Recommended Posts

On page 23, there is a section in grey on using white space.  The example shown is this:

print "Line 1\nLine2"; 

I tested this and it returns simply

 

Line 1 Line 2

 

I looked in the PHP manual and found that I can use \n in the nl2br function. I tried it using this code:

print nl2br("Line 1\nLine 2"); 

And that worked, outputting this:

 

Line 1

Line 2

 

Is this an error in the book, or am I missing something.  I checked the errata and found nothing.  

 

Clearly I found one way (maybe the only way?), but I am wondering if I am missing something about how it is explained in chapter 1?

 
Link to comment
Share on other sites

Sorry for the confusion about this! If you reread that sidebar on page 23, after that code, you'll see it says "Again, use of the newline character affects the HTML source code of the Web page, not what the end user will see rendered in the browser." If you use that code (not nl2br()) and then check the HTML source code of the resulting page, you'll see the effect. 

Link to comment
Share on other sites

 Share

×
×
  • Create New...