Massacres Posted November 21, 2006 Share Posted November 21, 2006 \n in double qoutes [i]should [/i]work, but it doesn't seem to be working. [code]<?php$TF=array("False","True");echo $TF[("hello"==="hello")];?>_blahblah_<?php echo "\n",$TF[0];?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/27937-php-line-break/ Share on other sites More sharing options...
Psycho Posted November 21, 2006 Share Posted November 21, 2006 Unless you are enclosing the line breaks within PRE tags, it will not be displayed as a line break on the page. It will be a line break in the HTML code. You need to echo < BR > tags to the page to make "displayed" line breaks. Quote Link to comment https://forums.phpfreaks.com/topic/27937-php-line-break/#findComment-127788 Share on other sites More sharing options...
wildteen88 Posted November 21, 2006 Share Posted November 21, 2006 It does work. But only in the source code. The reason for this becuase the browser ignores whitespace characters, such a \n \r \t etc. However if you go to View > Source in the browser you'll see that the whitespace characters have been parsed.What you'll need to do is is convert the line breaks to HTML line breaks [nobbc]<br />[/nobbc]. You can easily do this using the nl2br function.:[code=php:0]$someStr = 'this has \r\nnewlines \ncha\n\n\nrac\nters in \it!';// display $someStr without nlsbr function:echo $someStr . '<hr />';// display $someStr with nl2br function:echo nl2br($someStr);[/code] Quote Link to comment https://forums.phpfreaks.com/topic/27937-php-line-break/#findComment-128084 Share on other sites More sharing options...
Massacres Posted November 22, 2006 Author Share Posted November 22, 2006 EDIT2: I got the hunch that maybe I could use the HTML linebreak ( <br> ) and it worked, so I guess I misread your post. Thank you, this is very helpful.It didn't work; or I'm missing something;[color=red][b]Input:[/b][/color][code]<?php$someStr = 'this has \r\nnewlines \ncha\n\n\nrac\nters in \it!';echo nl2br($someStr);?>[/code][color=red][b]Output[/b][/color]this has \r\nnewlines \ncha\n\n\nrac\nters in \it!EDIT: Didn't mean to send so soon >_<It displays '\n', it just doesn't use it as a linebreak =/ Quote Link to comment https://forums.phpfreaks.com/topic/27937-php-line-break/#findComment-128333 Share on other sites More sharing options...
roopurt18 Posted November 22, 2006 Share Posted November 22, 2006 That's because it's enclosed in single quotes.The escape characters only work inside double quotes. Quote Link to comment https://forums.phpfreaks.com/topic/27937-php-line-break/#findComment-128357 Share on other sites More sharing options...
wildteen88 Posted November 22, 2006 Share Posted November 22, 2006 Oh crap!! Yeah whitespace characters only work in double quotes.This should work for you:[code=php:0]<?php$someStr = "this has \r\nnewlines \ncha\n\n\nrac\nters in \it!";echo nl2br($someStr);?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/27937-php-line-break/#findComment-128773 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.