3

My Data is reading data saved from the database (Text).

My problem is that it also has these characters: \r\n

How can I stop those characters showing?

1
  • Improve your question posting some code.
    – lorenzo-s
    Dec 27, 2011 at 8:27

3 Answers 3

5

Call the nl2br function with the database text in parameter before putting it in your textarea.

The \r\n characters are ASCII "invisible" characters, coding the carriage return and the line feed, or, if you prefer, the fact that there is a new line.

You need to change those ASCII code into HTML code, which is exactly what nl2br does.

3

Did you use mysql_real_escape_string() when pulling data from the DB? If so, stop that. You just have to use this when inserting data into the DB.

Another way: Use nl2br() before echoing.

-1

Whenever you want to store your data into database, you have to use nl2br() function in PHP to convert the \r\n to <br/> tag before saving data.

So, everywhere you want show that value in your project, everything will be fine.

3
  • It is much more important to use mysql_real_escape_string when writing to DB (for securitiy reasons). nl2br() is almost just for markup and beauty.
    – Armin
    Dec 27, 2011 at 8:32
  • Questioner did not ask about database security. The question was just about \r\n Dec 27, 2011 at 8:35
  • Aspects of security should be respected always!!
    – Armin
    Dec 27, 2011 at 9:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.