Jump to content

mysql_escape_string messes up line breaks \r\n


dsaba

Recommended Posts

I am using a html form to POST to a php page

 

on the php page I do this:

$rawtext = $_POST['field'];
$findlinebreak = strstr($rawtext, "\r\n");
        if ($findlinebreak != FALSE) {
        echo 'found a \r\n line break in the raw posted data!<br>';
        }
$escapedtext = mysql_escape_string($rawtext);

$rawtext = nl2br($rawtext);
echo "this is the rawtext with nl2br: $rawtext \n";

$escapetext = nl2br($escapedtext);
echo "this is the escapedtext with nl2br: $escapedtext \n";

 

 

it returns this:

 

found a \r\n line break in raw posted data!

this is the rawtext with nl2br: (this one outputs line breaks)

this one is the escapedtext with nl2br (this one does not output line breaks)

 

 

I wrote the above to help you understand my methods in trying to figure this out, but basically the problem is simple, if I mysql_escape_string() a string it messes up the \r\n line breaks...

Why? and How can I fix it?

 

 

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.