Jump to content
Larry Ullman's Book Forums

Recommended Posts

My question is mainly regarding Chapter 11, sub-chapter "Understanding HTTP Headers", Pg. 357 - but it also includes more general basic question.

 

There's a line on Pg. 357: "Before getting to the example, note that if a script uses multiple header( ) calls, each should be terminated by a newline (\n) as in the preceding code snippets."

 

Why? (The reason isn't explained in the book.)

 

Also. I see that Larry is using \n quite liberally in his code. I want to understand the reasons.

 

One of them, probably the main one, I guess, is to make the resulting HTML code more readable.

 

What are other possible reasons?

Link to post
Share on other sites

Weird. I cannot see anything in the manual that explains that. Non of the comments include header calls that uses newline ending either. I'm sure he explains it in the book if there's some special reason for this. (Maybe you just missed it?)

 

Yes. Newlines are applied because of legibility. It serves no other purpose functionally. Another reason could, however, be because a file is supposed to be read with PHP or another language. You need some way to tell this reader where a line ends, or it will read everything as a single line. Text editors applies these to the text without telling us, but they must exist. Please notice that line endings may depend of OS, so it's not save to only look for "\n"s.

ini_set('auto_detect_line_endings', true);

 

The line above will normalize the line endings for you.

  • Upvote 1
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...