Vivid Lust Posted November 8, 2008 Share Posted November 8, 2008 Hi all, How can I retain spaces which users make in textareas when saved in a database in a field which is ummm, set as "text". Say they press enter a couple of times... how could I retain that?? At the moment its just getting rid of two spaces or more... Thanks. Link to comment https://forums.phpfreaks.com/topic/131944-retaining-spaces-from-textareas-to-database/ Share on other sites More sharing options...
Yesideez Posted November 8, 2008 Share Posted November 8, 2008 First, a "space" is different from "enter" What are you losing exactly? Link to comment https://forums.phpfreaks.com/topic/131944-retaining-spaces-from-textareas-to-database/#findComment-685517 Share on other sites More sharing options...
genericnumber1 Posted November 8, 2008 Share Posted November 8, 2008 your problem is not the data being saved to the database, it's that when a browser renders html it skips multiple subsequent spaces and all line returns. You can maintain line breaks with nl2br() to change "enter hits" (line breaks) to <br /> tags that a browser will actually render. As for multiple subsequent spaces... I guess you could change all spaces to but that sounds like a waste of bandwidth and render time. alternatively you could encase it all in <pre></pre> tags Link to comment https://forums.phpfreaks.com/topic/131944-retaining-spaces-from-textareas-to-database/#findComment-685519 Share on other sites More sharing options...
Vivid Lust Posted November 8, 2008 Author Share Posted November 8, 2008 so i could do: $foo = nl2br($_POST['bar']); Link to comment https://forums.phpfreaks.com/topic/131944-retaining-spaces-from-textareas-to-database/#findComment-685537 Share on other sites More sharing options...
Yesideez Posted November 8, 2008 Share Posted November 8, 2008 That will preserve the carriage returns only, by converting them all to <br /> tags. As for the spaces at the end I can only suggest regex. Link to comment https://forums.phpfreaks.com/topic/131944-retaining-spaces-from-textareas-to-database/#findComment-685539 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.