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"; 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 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? 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 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. 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. 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. 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 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. Link to comment https://forums.phpfreaks.com/topic/241249-line-break-fails/#findComment-1239342 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.