Jump to content

PhP -> Line break


Massacres

Recommended Posts

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]
Link to comment
https://forums.phpfreaks.com/topic/27937-php-line-break/#findComment-128084
Share on other sites

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 =/
Link to comment
https://forums.phpfreaks.com/topic/27937-php-line-break/#findComment-128333
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.