geudrik Posted August 6, 2008 Share Posted August 6, 2008 When entering data througha text box to be stored in a mySql database, how do you preserve the white space when it gets displayed back onto a page? Eg: if i post a multi-paragraphed page, how do I keep the paragraphs seperated? ??? Link to comment https://forums.phpfreaks.com/topic/118530-preserving-whitespace/ Share on other sites More sharing options...
lemmin Posted August 6, 2008 Share Posted August 6, 2008 You could use regex to switch the line breaks to <br> tags: preg_replace("[\n]", "<br>", $content); Link to comment https://forums.phpfreaks.com/topic/118530-preserving-whitespace/#findComment-610229 Share on other sites More sharing options...
DarkWater Posted August 6, 2008 Share Posted August 6, 2008 Use the nl2br() function when outputting it. Link to comment https://forums.phpfreaks.com/topic/118530-preserving-whitespace/#findComment-610231 Share on other sites More sharing options...
discomatt Posted August 6, 2008 Share Posted August 6, 2008 You could also use a formatted version of the <pre></pre> tags. In order to preserve all whitespace outside of using pre you'll have to convert spaces to ' ' and tabs '\t' to several ' 's as well as use the nl2br function. Link to comment https://forums.phpfreaks.com/topic/118530-preserving-whitespace/#findComment-610264 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.