SieRobin Posted August 3, 2006 Share Posted August 3, 2006 Ok, for the forum on my site, when you post a reply and hit the enter button to make line breaks, it puts "rn" for each enter into the database.Anyone know why it would do that? Quote Link to comment Share on other sites More sharing options...
.josh Posted August 3, 2006 Share Posted August 3, 2006 those are the escape characters to make a new line. Quote Link to comment Share on other sites More sharing options...
SieRobin Posted August 3, 2006 Author Share Posted August 3, 2006 How do I rid of them? Quote Link to comment Share on other sites More sharing options...
SieRobin Posted August 3, 2006 Author Share Posted August 3, 2006 Or is there some way I can change the character? I just want it gone so it will work correctly, this hasn't happened before, just started today. Quote Link to comment Share on other sites More sharing options...
SieRobin Posted August 3, 2006 Author Share Posted August 3, 2006 Whyyyy in the world is it doing this? It's putting rn for a line break, HOW do I fix this? Quote Link to comment Share on other sites More sharing options...
manmadareddy Posted August 3, 2006 Share Posted August 3, 2006 You can just replace that character with your customize character using string functions.But while retrieving for disaply you must again need to replace you character with new line character. Quote Link to comment Share on other sites More sharing options...
SieRobin Posted August 3, 2006 Author Share Posted August 3, 2006 What exactly do you mean? Quote Link to comment Share on other sites More sharing options...
manmadareddy Posted August 3, 2006 Share Posted August 3, 2006 I hope your facing problem with newline characters.You just need to replace that character with new line characterwhile displaying. Quote Link to comment Share on other sites More sharing options...
hackerkts Posted August 3, 2006 Share Posted August 3, 2006 I believe he meantpreg_replace("rn", "\n", "words... words and words.."); Quote Link to comment Share on other sites More sharing options...
SieRobin Posted August 3, 2006 Author Share Posted August 3, 2006 [quote author=hackerkts link=topic=102818.msg408669#msg408669 date=1154587597]I believe he meantpreg_replace("rn", "\n", "words... words and words..");[/quote]Warning: preg_replace(): Delimiter must not be alphanumeric or backslash in /home/sierobin/public_html/forum.php on line 29That gives you an error. I still have a question though that wasn't answered.. I really don't understand why this is happening now, since it never has before. Quote Link to comment Share on other sites More sharing options...
manmadareddy Posted August 3, 2006 Share Posted August 3, 2006 preg_replace("/rn/", "\n", "words... words and words..");try this Quote Link to comment Share on other sites More sharing options...
.josh Posted August 3, 2006 Share Posted August 3, 2006 is this your own personal forum you are coding or some other script (like ipb, phpbb, etcc) that you are using? Quote Link to comment Share on other sites More sharing options...
Chetan Posted August 3, 2006 Share Posted August 3, 2006 but replacing rn in a sentence like "he is a stern guy" would make it"he is a ste guy"and i dont think he wants that and use this if you relly want to change rn = \n[code]<?php$text="I love...rnguess whatrnchocolates";$text=str_replace("rn", "\n", $text);echo $text;// Results:-// I love...// guess what// chocolates?>[/code] Quote Link to comment Share on other sites More sharing options...
HeyRay2 Posted August 3, 2006 Share Posted August 3, 2006 Are you performing a [b]stripslashes()[/b] on the reply text before it's added to the database?If so, that would change "\r\n" to "rn".Run a [b]str_replace()[/b] or a [b]preg_replace()[/b] instead of stripping slashes, change "\r\n" to "\n", then change "\n" to HTML line breaks, and you should be good to go:[code=php:0]$text = nl2br(preg_replace("/\r\n/", "\n", $_POST['text']));[/code] Quote Link to comment Share on other sites More sharing options...
SieRobin Posted August 3, 2006 Author Share Posted August 3, 2006 [quote author=Crayon Violent link=topic=102818.msg408918#msg408918 date=1154617461]is this your own personal forum you are coding or some other script (like ipb, phpbb, etcc) that you are using?[/quote]My own personal forum. Quote Link to comment Share on other sites More sharing options...
SieRobin Posted August 3, 2006 Author Share Posted August 3, 2006 [quote author=HeyRay2 link=topic=102818.msg408929#msg408929 date=1154618751]Are you performing a [b]stripslashes()[/b] on the reply text before it's added to the database?If so, that would change "\r\n" to "rn".Run a [b]str_replace()[/b] or a [b]preg_replace()[/b] instead of stripping slashes, change "\r\n" to "\n", then change "\n" to HTML line breaks, and you should be good to go:[code=php:0]$text = nl2br(preg_replace("/\r\n/", "\n", $_POST['text']));[/code][/quote]I tried this, it didn't work, gave me the same thing without it. Quote Link to comment Share on other sites More sharing options...
SieRobin Posted August 3, 2006 Author Share Posted August 3, 2006 [quote author=RockingGroudon link=topic=102818.msg408923#msg408923 date=1154617977]but replacing rn in a sentence like "he is a stern guy" would make it"he is a ste guy"and i dont think he wants that and use this if you relly want to change rn = \n[code]<?php$text="I love...rnguess whatrnchocolates";$text=str_replace("rn", "\n", $text);echo $text;// Results:-// I love...// guess what// chocolates?>[/code][/quote]This somewhat works, but I changed \n to [code]<br>[/code]. What's odd is that the \n will not work. I know this because for quoting on my forum I use "\n" to space the text out from the quote. But once it is submitted it doesn't put "\n" it puts rn in replace of that. What's also really odd is that it worked before, it just now decided not to work anymore. The only problem with it, is that if you line break twice, it will only inster ONE line break, not two. Quote Link to comment Share on other sites More sharing options...
HeyRay2 Posted August 3, 2006 Share Posted August 3, 2006 You didn't answer the question I posed.Are you performing any modifications on the reply text before it's submitted to the database?If so, we need to know what those modifications are so we know what state the text is in. Only then will we know what needs to be done to that text to get rid of your "rn" problem.My code will only work if you have not yet stripped the slashes from your reply text.Perhaps posting a snippet of your "reply" code would be a step in the right direction. Quote Link to comment Share on other sites More sharing options...
SieRobin Posted August 3, 2006 Author Share Posted August 3, 2006 [quote author=HeyRay2 link=topic=102818.msg408999#msg408999 date=1154623871]You didn't answer the question I posed.Are you performing any modifications on the reply text before it's submitted to the database?If so, we need to know what those modifications are so we know what state the text is in. Only then will we know what needs to be done to that text to get rid of your "rn" problem.My code will only work if you have not yet stripped the slashes from your reply text.Perhaps posting a snippet of your "reply" code would be a step in the right direction.[/quote]The script was pretty simple HeyRay2, all it really was, was a $_POST from the textarea on the form. Nothing is modified or even messed around with. It's straight forward posting information into the database.. that's all. Quote Link to comment Share on other sites More sharing options...
SieRobin Posted August 3, 2006 Author Share Posted August 3, 2006 Wow haha, ok now \n is working, do NOT ask why please, because I cannot give you that answer. It's working perfectly now, thank you everyone for taking out the time to help me with the problem :D I appreciate it.Woohoo! Quote Link to comment Share on other sites More sharing options...
HeyRay2 Posted August 3, 2006 Share Posted August 3, 2006 Glad to hear it started working again.If you're still interested in investigating why this happened, maybe answer the following:Have you recently changed anything in your forum code?Have you switch to a new web host?Have you upgraded to a new type / version of database?Have you upgraded to a new version of PHP?Also, a snippet of your "reply" code could still prove useful in this situation... ;) Quote Link to comment Share on other sites More sharing options...
SieRobin Posted August 3, 2006 Author Share Posted August 3, 2006 One small question though. For each thread you can view it basically with a title set in the link tag, so when you hold your cursor over the link it shows what was posted so you don't have to click on it to read it. Now if there is quotes or an apostrophe.. it won't display anything past the apostrophe or quote. I tried using, "addslashes" but it really doesn't do anything. How could I make it so you can read the entire thing? Quote Link to comment Share on other sites More sharing options...
SieRobin Posted August 4, 2006 Author Share Posted August 4, 2006 Anyone? Quote Link to comment Share on other sites More sharing options...
Chetan Posted August 4, 2006 Share Posted August 4, 2006 try using echo first so that you can see what it is doing, what it puts in the HTML Quote Link to comment Share on other sites More sharing options...
SieRobin Posted September 19, 2006 Author Share Posted September 19, 2006 I'm still having this problem, sure str_replace works good, but what if I wanted to post the word "turn" in? Then I would have a line break at the "rn" in turn.. therefore it doesn't work very well. I thought in PHP when you use a linebreak it's supposed to just output /n?I don't know, I need some help please, I'd like to have line breaks when you hit the enter button lol. Quote Link to comment 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.