DomMarx Posted June 12, 2013 Share Posted June 12, 2013 (edited) 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) 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 June 12, 2013 by DomMarx Quote Link to comment https://forums.phpfreaks.com/topic/279074-when-to-use-n-vs/ Share on other sites More sharing options...
Solution Irate Posted June 12, 2013 Solution Share Posted June 12, 2013 \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. Quote Link to comment https://forums.phpfreaks.com/topic/279074-when-to-use-n-vs/#findComment-1435554 Share on other sites More sharing options...
DomMarx Posted June 12, 2013 Author Share Posted June 12, 2013 Alright cool. Thanks man! Quote Link to comment https://forums.phpfreaks.com/topic/279074-when-to-use-n-vs/#findComment-1435555 Share on other sites More sharing options...
Zane Posted June 12, 2013 Share Posted June 12, 2013 \n Newlines will only ever "appear" in the source code. The same goes for \r RETURN; the tag is for HTML formatting and thus only functions in a browser. If you check the source code on something you are echoing , then you will clearly see it. Quote Link to comment https://forums.phpfreaks.com/topic/279074-when-to-use-n-vs/#findComment-1435558 Share on other sites More sharing options...
DomMarx Posted June 12, 2013 Author Share Posted June 12, 2013 So you don't really need \n then? Unless it's for cleaning up the source code? Quote Link to comment https://forums.phpfreaks.com/topic/279074-when-to-use-n-vs/#findComment-1435572 Share on other sites More sharing options...
Zane Posted June 12, 2013 Share Posted June 12, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/279074-when-to-use-n-vs/#findComment-1435603 Share on other sites More sharing options...
DomMarx Posted June 12, 2013 Author Share Posted June 12, 2013 Thanks Zane! Quote Link to comment https://forums.phpfreaks.com/topic/279074-when-to-use-n-vs/#findComment-1435631 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.