Forum Moderators: coopster

Message Too Old, No Replies

Unable to trim carriage return line feed

boring carriage return being echo in a textarea

         

dbarasuk

1:43 pm on Oct 27, 2009 (gmt 0)

10+ Year Member



Hello all,
I have a php script to display the content of a textarea to get redisplayed when a user hits the submit button with some missing field values.

What happens is the fact to see carriage returns and line feeds displayed like: \r\n. Everywhere the enter button has been hitted, you always see those boring signs when the textarea content gets reechoed. I tried the nl2br and the trim functions to remove them but could not. What can i do?

txs

Zipper

2:16 pm on Oct 27, 2009 (gmt 0)

10+ Year Member



Not sure, but it could be OS dependent since they tend to use different ASCII chars for line breaks. Try this,


str_replace(array("\r\n", "\r", "\n"), "<br />", $yourString);

eelixduppy

3:30 pm on Oct 27, 2009 (gmt 0)



Are you escaping the text before you are adding it to the text area? I'm pretty sure the newline isn't suppose to show in the text area unless it is escaped. Try stripping the slashes (stripslashes [php.net]) before you put it into the text area.

dbarasuk

5:13 pm on Oct 27, 2009 (gmt 0)

10+ Year Member



Indeed, i am using mysqli_real_escape_string function before echoing to the textarea since the textarea value is intended to be sent to the mysql database.

i think too, stripslashes is likely to solve this problem. i am going to try this and will let you know something.

thks

dbarasuk

7:23 pm on Oct 27, 2009 (gmt 0)

10+ Year Member




i tried the two suggestions mentionned here above but none of them could do the job.
more idea,
please

rocknbil

8:57 pm on Oct 27, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What happens is the fact to see carriage returns and line feeds displayed like: \r\n.

First, this is what you see- but is it really what's in the page code?

View the source of the page, look for the text area content.

Do you see \r\n when you view source, or

%5cr%5cn

or some other html-ized entity?

It could be encoded. Whatever the case, between submit and return to the form, something in your program is doing this.

bkeep

9:11 pm on Oct 27, 2009 (gmt 0)

10+ Year Member



eelixduppy is right if you are prepping for the db but then dumping to the screen that is the issue. I had something similar happen a little while ago and that is what I found.

In the event an error is found either missing data or improper data don't run the data through mysql_real_escape_string until you are ready to put data in the db run it through something like this $var = htmlentities(trim($var), ENT_QUOTES, "UTF-8");

Your mileage may vary but as I said I had issues and that was my solution.