JParishy Posted April 5, 2007 Share Posted April 5, 2007 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 More sharing options...
MadTechie Posted April 5, 2007 Share Posted April 5, 2007 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 Link to comment https://forums.phpfreaks.com/topic/45670-detecting-the-end-of-a-line/#findComment-221799 Share on other sites More sharing options...
JParishy Posted April 5, 2007 Author Share Posted April 5, 2007 Ahh, ok. I'll try it out. Link to comment https://forums.phpfreaks.com/topic/45670-detecting-the-end-of-a-line/#findComment-221800 Share on other sites More sharing options...
trq Posted April 5, 2007 Share Posted April 5, 2007 Use nl2br when displaying the data. Leave the data in its natural state when saving it to the database though. Link to comment https://forums.phpfreaks.com/topic/45670-detecting-the-end-of-a-line/#findComment-221801 Share on other sites More sharing options...
JParishy Posted April 5, 2007 Author Share Posted April 5, 2007 Okay, thanks guys. It works now. So what did you think? This is my first PHP project. Link to comment https://forums.phpfreaks.com/topic/45670-detecting-the-end-of-a-line/#findComment-221808 Share on other sites More sharing options...
MadTechie Posted April 5, 2007 Share Posted April 5, 2007 yeah not bad.. my first project, <?php echp "Hello World"; ?> i'll get it to work one day... ~Sighs~ Oh yeah Click Solved Link to comment https://forums.phpfreaks.com/topic/45670-detecting-the-end-of-a-line/#findComment-221810 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.