Jump to content

Archived

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

SieRobin

Weird Problem

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Whyyyy in the world is it doing this? It's putting rn for a line break, HOW do I fix this?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
I hope your facing problem with newline characters.
You just need to replace that character with new line character
while displaying.

Share this post


Link to post
Share on other sites
I believe he meant
preg_replace("rn", "\n", "words... words and words..");

Share this post


Link to post
Share on other sites
[quote author=hackerkts link=topic=102818.msg408669#msg408669 date=1154587597]
I believe he meant
preg_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 29

That 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.

Share this post


Link to post
Share on other sites
is this your own personal forum you are coding or some other script (like ipb, phpbb, etcc) that you are using?

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
[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.

Share this post


Link to post
Share on other sites
[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.

Share this post


Link to post
Share on other sites
[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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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... ;)

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
try using echo first so that you can see what it is doing, what it puts in the HTML

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

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.