Jump to content


Photo

Weird Problem


  • Please log in to reply
24 replies to this topic

#1 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 03 August 2006 - 03:45 AM

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?

#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 03 August 2006 - 04:11 AM

those are the escape characters to make a new line. 
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 03 August 2006 - 04:12 AM

How do I rid of them?

#4 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 03 August 2006 - 04:28 AM

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.

#5 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 03 August 2006 - 06:13 AM

Whyyyy in the world is it doing this? It's putting rn for a line break, HOW do I fix this?

#6 manmadareddy

manmadareddy
  • Members
  • PipPipPip
  • Advanced Member
  • 50 posts

Posted 03 August 2006 - 06:32 AM

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.

#7 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 03 August 2006 - 06:43 AM

What exactly do you mean?

#8 manmadareddy

manmadareddy
  • Members
  • PipPipPip
  • Advanced Member
  • 50 posts

Posted 03 August 2006 - 06:45 AM

I hope your facing problem with newline characters.
You just need to replace that character with new line character
while displaying.

#9 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 03 August 2006 - 06:46 AM

I believe he meant
preg_replace("rn", "\n", "words... words and words..");

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#10 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 03 August 2006 - 06:55 AM

I believe he meant
preg_replace("rn", "\n", "words... words and words..");


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.

#11 manmadareddy

manmadareddy
  • Members
  • PipPipPip
  • Advanced Member
  • 50 posts

Posted 03 August 2006 - 07:38 AM

preg_replace("/rn/", "\n", "words... words and words..");
try this

#12 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 03 August 2006 - 03:04 PM

is this your own personal forum you are coding or some other script (like ipb, phpbb, etcc) that you are using?
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#13 Chetan

Chetan
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts
  • LocationIndia

Posted 03 August 2006 - 03:12 PM

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
<?php
$text="I love...rnguess whatrnchocolates";
$text=str_replace("rn", "\n", $text);
echo $text;
// Results:-
// I love...
// guess what
// chocolates
?>

I am a PHP Guru, ask me questions if you want to

#14 HeyRay2

HeyRay2
  • Members
  • PipPipPip
  • Advanced Member
  • 223 posts

Posted 03 August 2006 - 03:25 PM

Are you performing a stripslashes() on the reply text before it's added to the database?

If so, that would change "\r\n" to "rn".

Run a str_replace() or a preg_replace() instead of stripping slashes, change "\r\n" to "\n", then change "\n" to HTML line breaks, and you should be good to go:

$text = nl2br(preg_replace("/\r\n/", "\n", $_POST['text']));


#15 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 03 August 2006 - 04:35 PM

is this your own personal forum you are coding or some other script (like ipb, phpbb, etcc) that you are using?


My own personal forum.

#16 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 03 August 2006 - 04:38 PM

Are you performing a stripslashes() on the reply text before it's added to the database?

If so, that would change "\r\n" to "rn".

Run a str_replace() or a preg_replace() instead of stripping slashes, change "\r\n" to "\n", then change "\n" to HTML line breaks, and you should be good to go:

$text = nl2br(preg_replace("/\r\n/", "\n", $_POST['text']));


I tried this, it didn't work, gave me the same thing without it.

#17 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 03 August 2006 - 04:47 PM

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

<?php
$text="I love...rnguess whatrnchocolates";
$text=str_replace("rn", "\n", $text);
echo $text;
// Results:-
// I love...
// guess what
// chocolates
?>


This somewhat works, but I changed \n to
<br>
. 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.

#18 HeyRay2

HeyRay2
  • Members
  • PipPipPip
  • Advanced Member
  • 223 posts

Posted 03 August 2006 - 04:51 PM

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.

#19 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 03 August 2006 - 04:53 PM

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.


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.

#20 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 03 August 2006 - 04:57 PM

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!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users