angel1987 Posted September 10, 2010 Share Posted September 10, 2010 I am using textarea to get data and entering it into database using addslashes and mysql_real_escape_string $text = $_POST['txttext']; $text = addslashes($text); $text = mysql_real_escape_string($text); Then displaying the data from database on other page using stripslashes and htmlentities $text = stripslashes(htmlentities($rows['text'])); echo nl2br($text); Entire text stretches across the screen and shows in 1 line. Is it because use of addslashes, stripslashes etc ? Quote Link to comment https://forums.phpfreaks.com/topic/213029-nl2br-not-working/ Share on other sites More sharing options...
rwwd Posted September 10, 2010 Share Posted September 10, 2010 you could use wordwrap() if all else fails... Looks to me like you are overdoing the slashes, mysql_real_escape_string() does exactly the same thing as addslashes() you you might want to consider revising your method. Try stripping it down to raw data, and then progressing from there - but mysql_real_escape_string() is the preferred method of making the user generated data safer for injection into your DB. Also you have htmlentities on the wrong side, you use that to make the HTML data database safe, you dont really need to use it for preparation for use in the textarea. Have a play though, see what fits, but I find wordwrap() to be quite useful. Cheers, Rw Quote Link to comment https://forums.phpfreaks.com/topic/213029-nl2br-not-working/#findComment-1109492 Share on other sites More sharing options...
YourNameHere Posted September 10, 2010 Share Posted September 10, 2010 I am using textarea to get data and entering it into database using addslashes and mysql_real_escape_string $text = $_POST['txttext']; $text = addslashes($text); $text = mysql_real_escape_string($text); Then displaying the data from database on other page using stripslashes and htmlentities $text = stripslashes(htmlentities($rows['text'])); echo nl2br($text); Entire text stretches across the screen and shows in 1 line. Is it because use of addslashes, stripslashes etc ? $text = $_POST['txttext']; $text = nl2br($text); $text = mysql_real_escape_string($text); That is all that is necessary. nl2br() needs to be done before you place it in the DB. then you can just echo the text. Quote Link to comment https://forums.phpfreaks.com/topic/213029-nl2br-not-working/#findComment-1109493 Share on other sites More sharing options...
wildteen88 Posted September 10, 2010 Share Posted September 10, 2010 I am using textarea to get data and entering it into database using addslashes and mysql_real_escape_string $text = $_POST['txttext']; $text = addslashes($text); $text = mysql_real_escape_string($text); Then displaying the data from database on other page using stripslashes and htmlentities $text = stripslashes(htmlentities($rows['text'])); echo nl2br($text); Entire text stretches across the screen and shows in 1 line. Is it because use of addslashes, stripslashes etc ? $text = $_POST['txttext']; $text = nl2br($text); $text = mysql_real_escape_string($text); That is all that is necessary. nl2br() needs to be done before you place it in the DB. then you can just echo the text. No, it shouldn't! It is best to call nl2br when you are displaying the data from the database. I think the issue is with addslashes/stripslashes. There is no need to call addslashes if you're using mysql_real_escape_string. You can also remove the call to strip_slashes here $text = stripslashes(htmlentities($rows['text'])); This is most probably affecting the newlines within your text and thus nl2br doesn't work. Quote Link to comment https://forums.phpfreaks.com/topic/213029-nl2br-not-working/#findComment-1109499 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.