dadamssg Posted April 6, 2009 Share Posted April 6, 2009 i having a place were users can leave comments and replies in a text box. i want whenever they push the enter button on the keyboard and it goes to the next line, i want that to show up when i retrieve it from the db...how would i program the Enter button to produce a linebreak? this ==> blah blah blah blah is outputted as blah blah blah blah Quote Link to comment https://forums.phpfreaks.com/topic/152880-line-breaks/ Share on other sites More sharing options...
tmh766 Posted April 6, 2009 Share Posted April 6, 2009 Hey just try out str_replace("\r",'<br>',$string); If that does not work, replace the "\r" with "\r\n" Quote Link to comment https://forums.phpfreaks.com/topic/152880-line-breaks/#findComment-802859 Share on other sites More sharing options...
wildteen88 Posted April 6, 2009 Share Posted April 6, 2009 use nl2br Quote Link to comment https://forums.phpfreaks.com/topic/152880-line-breaks/#findComment-802864 Share on other sites More sharing options...
dadamssg Posted April 6, 2009 Author Share Posted April 6, 2009 ok should i use that before or after this function ive created? function clean_post($variable) { $cxn = mysqli_connect($host,$user,$passwd,$dbname) or die("Couldn't connect"); return mysqli_real_escape_string($cxn, strip_tags($variable)); } Quote Link to comment https://forums.phpfreaks.com/topic/152880-line-breaks/#findComment-802866 Share on other sites More sharing options...
tmh766 Posted April 6, 2009 Share Posted April 6, 2009 You can store it in the database either way. If you store it in the database without replacing the enters with <br>s, just be sure to format it when you display it in HTML. The reason you have to replace the enters ("\r") with <br>, is HTML does not care about white space. Quote Link to comment https://forums.phpfreaks.com/topic/152880-line-breaks/#findComment-802873 Share on other sites More sharing options...
premiso Posted April 6, 2009 Share Posted April 6, 2009 You should store it in the database in it's raw format (not as <br>) meaning the "\n" then use the function wildteen pointed out when retrieving the data from the database for displaying. Reason for this, you may want to use that data in something other than html output (xml, csv, text) etc. This way you can easily do what you want with the data as necessary. Quote Link to comment https://forums.phpfreaks.com/topic/152880-line-breaks/#findComment-802881 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.