Striping newline's from a string
Moderator: General Moderators
Striping newline's from a string
I've got a textarea that the user may type in. The idea is to save the entered text as $message into a file, onto one line.
Later I have a program that opens the file with the messages and prints them in a table.
The idea is to have one message per row in this table, However, if the user decides to make a new line in the text area, they can manipulate the file and make multiple messages at once.
This is ugly for my orginazation.
Is there any way that I can take these \n out of the middle of the string? I've tried trim(), but it only works if the vermin are at the begining or end of the string.
Thank you for any help.
Later I have a program that opens the file with the messages and prints them in a table.
The idea is to have one message per row in this table, However, if the user decides to make a new line in the text area, they can manipulate the file and make multiple messages at once.
This is ugly for my orginazation.
Is there any way that I can take these \n out of the middle of the string? I've tried trim(), but it only works if the vermin are at the begining or end of the string.
Thank you for any help.
Awesome!
Thanks for pointing me in the right direction. I see what your saying about the user wanting the format intact, so what I did was I had the program that writes the message to replace \n with some obscure set of characters that are not likly to come together (EX: `~`) and then write them.
in the program that reads the file, I have str_replace() read the `~` and turn it into a <br />.
Works well. I did this because I don't know about XML, of course I haven't searched this site for information regarding it yet, but I will.
Thank you for your help!
Thanks for pointing me in the right direction. I see what your saying about the user wanting the format intact, so what I did was I had the program that writes the message to replace \n with some obscure set of characters that are not likly to come together (EX: `~`) and then write them.
in the program that reads the file, I have str_replace() read the `~` and turn it into a <br />.
Works well. I did this because I don't know about XML, of course I haven't searched this site for information regarding it yet, but I will.
Thank you for your help!
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
I don't know if this would work, but I do know you need to process newlines with double quotes to use them literally. Perhaps use single quotes when processing your data?
Disclaimer: I've been writting a paper for 5 hours now, I'm tired, and I certainly may be off the ball.
Ahem.. Feyd, correct me will ya?
Disclaimer: I've been writting a paper for 5 hours now, I'm tired, and I certainly may be off the ball.
Ahem.. Feyd, correct me will ya?
.... ah.
Yeah... I want a dislcaimer too!
Orginally I was taking out \n and in the html I was putting it back in. But html doesn't treat \n like a newline, so I changed it to <br />.
Hmm, well thanks for pointing that out to me so quickly!
Jcart,
I'm confused, do you mean something like '$message' or ""$message""? If so, how would this help?
Yeah... I want a dislcaimer too!
Orginally I was taking out \n and in the html I was putting it back in. But html doesn't treat \n like a newline, so I changed it to <br />.
Hmm, well thanks for pointing that out to me so quickly!
Jcart,
I'm confused, do you mean something like '$message' or ""$message""? If so, how would this help?
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Have you looked at nl2br()? It does what you are doing for you.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
I did not know that. How about Matthew Mullenwegs New nl2br function?