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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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