Reputation: 106
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.
Upvotes: 0
Views: 69
Reputation: 146460
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.)
Upvotes: 1
Reputation: 2216
you just need to replace the \n or \r to blank like this:
$post= trim(preg_replace('/\s+/', ' ', $_POST['MESSAGE']));
Upvotes: 1