0

So I have one problem, that I don't know how to fix. Everytime I enter in textarea "Enter", it posts them not like spaces, but like "\n". For expample, I enter "Hi! [hit enter key] My name is Richard.", it will come out like "Hi!\nMy name is Richard. Code is simple:

$post = mysql_real_escape_string(htmlspecialchars($_POST['MESSAGE']));
echo $post;

Sooo, anyone - please help.

user3362165
  • 106
  • 2
  • 10

2 Answers2

1

this might help you

you just need to replace the \n or \r to blank like this:

$post= trim(preg_replace('/\s+/', ' ', $_POST['MESSAGE']));
Community
  • 1
  • 1
Idan Magled
  • 2,100
  • 1
  • 22
  • 32
1

You are encoding the input data with mysql_real_escape_string() to convert it into a literal SQL string valid for MySQL. The correct way to encode a Unix line feed is \n. Thus you're getting the expected result.

(You're also using the deprecated MySQL extension but I suppose you're aware of that.)

Álvaro González
  • 135,557
  • 38
  • 250
  • 339