Jump to content

When to use \n vs <br/> ?


DomMarx
Go to solution Solved by Irate,

Recommended Posts

Hi Guys,

 

I'm new here and just started learning PHP a couple of days ago. I have to say it's not nearly as intense as I thought it would be (coming from the simple html/css world)  :happy-04:

 

Anyways, I'm at the point where i'm learning about the /n line break. I was testing it in dreamweaver and saw that none of the browsers (Firefox, Safari, Chrome, etc.) recognize it, which makes perfect sense since browsers don't understand the PHP language. So I was wondering, when and where is the \n line break useful? I know you can spot the break if you check the source code from the browser, but other than that, there is no change on the front-end.

 

Thanks guys!

Edited by DomMarx
Link to comment
Share on other sites

  • Solution

\n is used for plaintext.

Since PHP again does not support <br> and \n isn't written directly into the browser (even though <br>s are recognized by JavaScript as \n), you can use string nl2br( string $string ) to give out a proper HTML-formated string.

Link to comment
Share on other sites

So you don't really need \n then? Unless it's for cleaning up the source code?

Exactly.  But they also come in handy for writing source code for things such as email headers. By putting \r\n after each mail header you allow sendmail to distinguish the characteristics of that message and display them accordingly.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.