aliento Posted March 24, 2013 Share Posted March 24, 2013 (edited) Hello, i use mysql_real_escape_string() to avoid sql injections but it escapes and line breaks \n. What should i do to keep the line breaks from the form and be protected by injections. Thank you Edited March 24, 2013 by aliento Quote Link to comment https://forums.phpfreaks.com/topic/276086-avoid-sql-injection-but-still-have-break-lines/ Share on other sites More sharing options...
Solution PaulRyan Posted March 24, 2013 Solution Share Posted March 24, 2013 (edited) When outputting the data, use nl2br to convert line ending characters to new lines. Take this for example: <?PHP $string = "This is a string. \r\n This is on a new line."; echo 'Without nl2br() <br> "'. $string.'"'; echo '<br>---------------------------<br>'; echo 'With nl2br() <br> "'. nl2br($string) .'"'; ?> Edited March 24, 2013 by PaulRyan Quote Link to comment https://forums.phpfreaks.com/topic/276086-avoid-sql-injection-but-still-have-break-lines/#findComment-1420716 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.