unemployment Posted July 6, 2011 Share Posted July 6, 2011 Why won't these break to a new line? echo "{$c['blue']}" . "\n"; echo $c['green'] . "\n"; Quote Link to comment https://forums.phpfreaks.com/topic/241249-line-break-fails/ Share on other sites More sharing options...
wildteen88 Posted July 6, 2011 Share Posted July 6, 2011 It does. The problem is web browsers ignores the new line characters (\n). You need to use the <br /> html tag in order for the browser to display text on a new line. PHP has a function for converting new line characters to <br /> tags called nl2br Quote Link to comment https://forums.phpfreaks.com/topic/241249-line-break-fails/#findComment-1239202 Share on other sites More sharing options...
unemployment Posted July 6, 2011 Author Share Posted July 6, 2011 It does. The problem is web browsers ignores the new line characters (\n). You need to use the <br /> html tag in order for the browser to display text on a new line. PHP has a function for converting new line characters to <br /> tags called nl2br oh ok... so what is the point of using \n or \r? Quote Link to comment https://forums.phpfreaks.com/topic/241249-line-break-fails/#findComment-1239204 Share on other sites More sharing options...
xyph Posted July 6, 2011 Share Posted July 6, 2011 Any time you want a true linebreak, and not an HTML linebreak Quote Link to comment https://forums.phpfreaks.com/topic/241249-line-break-fails/#findComment-1239206 Share on other sites More sharing options...
AbraCadaver Posted July 6, 2011 Share Posted July 6, 2011 Any time you want a true linebreak, and not an HTML linebreak Yes, such as when you view source, output in a shell, output inside HTML pre tags, in a textarea, etc. Quote Link to comment https://forums.phpfreaks.com/topic/241249-line-break-fails/#findComment-1239210 Share on other sites More sharing options...
unemployment Posted July 6, 2011 Author Share Posted July 6, 2011 Any time you want a true linebreak, and not an HTML linebreak Yes, such as when you view source, output in a shell, output inside HTML pre tags, in a textarea, etc. So it seems like this is more for just making your code look nice. Quote Link to comment https://forums.phpfreaks.com/topic/241249-line-break-fails/#findComment-1239239 Share on other sites More sharing options...
xyph Posted July 6, 2011 Share Posted July 6, 2011 PHP isn't just for HTML. You use line breaks in text files, for example. PHP can generate text files. Quote Link to comment https://forums.phpfreaks.com/topic/241249-line-break-fails/#findComment-1239240 Share on other sites More sharing options...
AyKay47 Posted July 6, 2011 Share Posted July 6, 2011 they are also used for plain text as xyph said...like with the mail() function Quote Link to comment https://forums.phpfreaks.com/topic/241249-line-break-fails/#findComment-1239247 Share on other sites More sharing options...
unemployment Posted July 7, 2011 Author Share Posted July 7, 2011 Oh right. I have used this before in my mail functions it's just been a while since i've written one. Quote Link to comment https://forums.phpfreaks.com/topic/241249-line-break-fails/#findComment-1239342 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.