techker Posted September 9, 2017 Share Posted September 9, 2017 Hey guys i have a for to upload for a car dealership i did ,in the form there is a text box for descrption. the guy wants to be able to insert a description like: ........................... this is a car test .features one .features 2 ....... this car is fully equipeed... .......................... but now the form insert in the database all messt up it becomes one text... is there a way to insert it in the database as he puts it? Quote Link to comment Share on other sites More sharing options...
Barand Posted September 9, 2017 Share Posted September 9, 2017 HTML treats all whitespace (including newlines) as a single space. When outputting text with newlne chars, use nl2br($text) to insert the <br> tags required by HTML Quote Link to comment Share on other sites More sharing options...
techker Posted September 9, 2017 Author Share Posted September 9, 2017 so the output would be $string = ".echo row['description'];."; echo nl2br($string); Quote Link to comment Share on other sites More sharing options...
Sepodati Posted September 9, 2017 Share Posted September 9, 2017 Unless your doing something to the data before it goes into the database, all those newlines are there. So as mentioned, the problem is probably when you display. nl2br() will help here, but you should also use htmlentities(). This will ensure anything typed into the box is displayed exactly as typed and not evaluated as HTML. echo nl2br(htmlentities($row['description'])); The takeaway here is that you process the data for where it's going. If it's going on the database, process through a prepared statement. If it's going into an HTML document, process it as above. If it's going into email, maybe there's another processing. etc, etc. Process for where it's going at the time it goes there. i.e. don't prices for HTML as it goes into the database. Hopefully that helps. Quote Link to comment Share on other sites More sharing options...
techker Posted September 9, 2017 Author Share Posted September 9, 2017 interesting. thx for the info i will read up on it. Quote Link to comment 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.