ricmetal Posted March 27, 2009 Share Posted March 27, 2009 hey, how do i keep line breaks using these code lines? inserting intot the db $var = mysql_real_escape_string($prevar); outputting from the db $var = stripslashes($varFromDb); $var2 = htmlspecialchars($var, ENT_QUOTES); ? thanks Quote Link to comment https://forums.phpfreaks.com/topic/151365-solved-how-do-i-keep-line-breaks-with-this-code/ Share on other sites More sharing options...
Mr.Shawn Posted March 27, 2009 Share Posted March 27, 2009 Perhaps you can try this method str_replace('<br>', '<br>', $var); Quote Link to comment https://forums.phpfreaks.com/topic/151365-solved-how-do-i-keep-line-breaks-with-this-code/#findComment-795009 Share on other sites More sharing options...
Mark Baker Posted March 27, 2009 Share Posted March 27, 2009 Insert the code into the DB without trying to change line breaks. When you subsequently retrieve it from the DB, and want to display it, use the nl2br() function Quote Link to comment https://forums.phpfreaks.com/topic/151365-solved-how-do-i-keep-line-breaks-with-this-code/#findComment-795014 Share on other sites More sharing options...
Mr.Shawn Posted March 27, 2009 Share Posted March 27, 2009 So if we use the nl2br() function, the function itself will change \n to <br>? Quote Link to comment https://forums.phpfreaks.com/topic/151365-solved-how-do-i-keep-line-breaks-with-this-code/#findComment-795016 Share on other sites More sharing options...
Yesideez Posted March 27, 2009 Share Posted March 27, 2009 Correct but not <br> but to <br /> Quote Link to comment https://forums.phpfreaks.com/topic/151365-solved-how-do-i-keep-line-breaks-with-this-code/#findComment-795017 Share on other sites More sharing options...
ricmetal Posted March 27, 2009 Author Share Posted March 27, 2009 Insert the code into the DB without trying to change line breaks. When you subsequently retrieve it from the DB, and want to display it, use the nl2br() function when i insert the data to the db without changing line breaks the db is populated with a <br> when retreiving, the <br> stays and doesnt perform a line break, when using the nl2br() function @mr shawn i never get those chars to replace in the first place Quote Link to comment https://forums.phpfreaks.com/topic/151365-solved-how-do-i-keep-line-breaks-with-this-code/#findComment-795027 Share on other sites More sharing options...
irkevin Posted March 27, 2009 Share Posted March 27, 2009 can you post the actual code you have plz? Quote Link to comment https://forums.phpfreaks.com/topic/151365-solved-how-do-i-keep-line-breaks-with-this-code/#findComment-795076 Share on other sites More sharing options...
Mr.Shawn Posted March 27, 2009 Share Posted March 27, 2009 @ricmetal that method would only work after you had use htmlspecialchars() function. It is just to replace the special chars back to tags. Quote Link to comment https://forums.phpfreaks.com/topic/151365-solved-how-do-i-keep-line-breaks-with-this-code/#findComment-795127 Share on other sites More sharing options...
ricmetal Posted March 27, 2009 Author Share Posted March 27, 2009 @ricmetal that method would only work after you had use htmlspecialchars() function. It is just to replace the special chars back to tags. but after htmlspecialchars, the special chars are changed to tags...and the tags aren't rendered. i dont know why. please help Quote Link to comment https://forums.phpfreaks.com/topic/151365-solved-how-do-i-keep-line-breaks-with-this-code/#findComment-795441 Share on other sites More sharing options...
ricmetal Posted March 27, 2009 Author Share Posted March 27, 2009 okay, i got it. it works fine with using nl2br after using the htmlspecialchars. ps. i failed to see that i was fetching some data to insert to the db from innerHtml, so the br tag was appearing in the db on those data fields. Quote Link to comment https://forums.phpfreaks.com/topic/151365-solved-how-do-i-keep-line-breaks-with-this-code/#findComment-795534 Share on other sites More sharing options...
MadnessRed Posted March 27, 2009 Share Posted March 27, 2009 okay, i got it. it works fine with using nl2br after using the htmlspecialchars. ps. i failed to see that i was fetching some data to insert to the db from innerHtml, so the br tag was appearing in the db on those data fields. becuase < is changed to < so you will see the tags Quote Link to comment https://forums.phpfreaks.com/topic/151365-solved-how-do-i-keep-line-breaks-with-this-code/#findComment-795535 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.