dsaba Posted June 8, 2007 Share Posted June 8, 2007 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? Link to comment https://forums.phpfreaks.com/topic/54696-mysql_escape_string-messes-up-line-breaks-rn/ Share on other sites More sharing options...
dsaba Posted June 8, 2007 Author Share Posted June 8, 2007 ah an update, i tried using mysql_real_escape_string as well, it does the same thing as mysql_escape_string so both do the same thing and mess up the line breaks somehow Link to comment https://forums.phpfreaks.com/topic/54696-mysql_escape_string-messes-up-line-breaks-rn/#findComment-270487 Share on other sites More sharing options...
cooldude832 Posted June 8, 2007 Share Posted June 8, 2007 its designed to escape characters thus "mysql_escape_string" Link to comment https://forums.phpfreaks.com/topic/54696-mysql_escape_string-messes-up-line-breaks-rn/#findComment-270492 Share on other sites More sharing options...
kdsxchris Posted June 8, 2007 Share Posted June 8, 2007 I didn't test this, but I think when you use mysql_query to retrieve the data, it will return the data the way it was BEFORE any mysql_escape_string, so it will return it the way you want as in $rawtext. Link to comment https://forums.phpfreaks.com/topic/54696-mysql_escape_string-messes-up-line-breaks-rn/#findComment-270493 Share on other sites More sharing options...
cooldude832 Posted June 8, 2007 Share Posted June 8, 2007 there is also something you can look into with magic_quotes Link to comment https://forums.phpfreaks.com/topic/54696-mysql_escape_string-messes-up-line-breaks-rn/#findComment-270495 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.