转发到php服务器时,textarea中的 被解释

So I enter

hello my friend !

into a textarea. Then I store it into db, I retrieve it, and what I get is

hello

my friend
!

But I did not want the get translated into actual newlines.

So this is my example setup:

<textarea name="mytextarea">$mytext</textarea>

on the server i do:

store

$mydbtextstore = $_POST["mytextarea"];

$modsql = " UPDATE mytable SET text = " . "'" . $mydbtextstore . "'" ;
mysql_query($modsql, $conn) or die(mysql_error());

retrieve

$descSQL = " SELECT  text
               FROM mytable;"
$descRes = mysql_query($descSQL, $conn) or die(mysql_error());
$descRow = mysql_fetch_array($descRes);
$mytext = $descRow["text"];

What am I missing? The textarea MUST reproduce and contain this:

You need to escape backslashes with another backslashes. Funny, right?

So after you submitted your text do like this:

$text = str_replace('\\', '\\\\', $text);

so you will have following:

hello \
 \
 my friend \
 !

and when you insert it in your database it will look like a string with only one backslashes

You could use a str_replace like this, after the retrieving of the data.

$mytext = str_replace("\","&#92;",$mytext);

You will replace the slash with its html-entity if you use this code.

EDIT: or use htmlentities on the whole string.