Jump to content

Detecting the end of a line.


JParishy

Recommended Posts

I am currently writing a blog (You can find it at http://dev.jparishy.com/). When you post, it does not recognize the end of a line, so:

 

Hello,

My Name Is Julius,

How are you?

..

Becomes

..

Hello,My Name Is Julius,How are you?

 

I tried,

$message = str_replace("\n", "<br>", $message);

 

because everything echo'd is rendered as html, and this worked. But, when you go to edit a post, it keeps on adding the "<br_>'s." (<-HTML is active :))

 

So,

Hello,

 

how are you?

 

What is your name?

 

would be:

Hello,

 

 

how are you?

 

 

What is your name?

 

And it will continue to seperate the lines each time you edit the file. I could just neglect to do,

$message = str_replace("\n", "<br>", $message);

when editing, but then any new lines will not be seperated.

 

Overall, my question is, are there any functions/special variables (like 'EOF' in C) that will work on lines (not in a file) to see if it is the end of a line? I hope you know what I mean.

 

Thank you.

 

-Julius P.

Link to comment
https://forums.phpfreaks.com/topic/45670-detecting-the-end-of-a-line/
Share on other sites

what if you used

$message = str_replace("\n", "<br>", $message);

for displaying the message but use

$message = str_replace("<br>", "\n", $message);

just before the editing screen

 

also you can use

nl2br — Inserts HTML line breaks before all newlines in a string
Description
string nl2br ( string $string )

Returns string with '<br />' inserted before all newlines.

 

 

 

LOL ok added some code tags to my post

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.