tags:

views:

81

answers:

1

I have a textarea that I need to put a new line into with some dashes above. I have tried nl2br but that just echos the
tag. I have also tried to concat the "\n" but it is ignored.

What this is for is an email like system. When the user replies to an email, I want the old message below with a seperator like a few dashes. I can't get this to work though.

new message starts here

--------------
old message here

Can someone please give a hand?

Thanks.

A: 

Try a return character: \r

According to this article, the \n newline character should work. What is happening when you are inserting the \n character into the string using double quotes?

This works for me:

 <textarea>test
testing</textarea>

it properly creates the next line. Check to make sure your source code looks something like that, with n actual line break in the source where you want it to be.

Chacha102
Thanks chacha. brb.
Hey Chacha, that doesn't work either. It's totally ignored.
Do you get anything at all? Is it displaying in the textarea?
Chacha102
Well, nothing happens when I insert the newline character. Now, I'm using trim() on that variable and I'm wondering if that may have something to do with it.
No, the \r and \n are not displaying at all.
Trim gets rid of new lines in and other empty space variables at the front and back of the string. This string will be trimmed `test\n` to `test`, this won't: `test \n test`
Chacha102
I'd try to remove the trim, and see if it works.
Chacha102
Ok, that's what I thought. I just removed the trim function but it is still doing the exact same thing. I'm stumped.
Could you show me some source code? It would be easier to debug.
Chacha102
$message = "\r\r------".$vals['message']; is what I'm using
`$message = "\r\n\r\n-----".$vals['message'];`
Matthew Scharley
Try replacing those \r with \n, and then do you do anything else to the variables. (You should have already taken out the trim).
Chacha102
`"\r\r"` means nothing to any modern system. `"\n\n"` should probably work though. `"\r\n\r\n"` will work anywhere though.
Matthew Scharley
Chacha, I got it, thank you very much! I have a "create" method that I forgot about that also had trim() removing the newline character. The problem was that I was testing this within the "reply" method and was why I couldn't see the results. :/
Thank you for that Matthew. I will keep that in mind. :)
If you found my answer to be your solution, please accept the answer by using the giant Checkbox near the top of my answer.
Chacha102
Already did. :) Thanks again my friend!