dbillings Posted July 16, 2007 Share Posted July 16, 2007 I have a problem understanding how I can submit form data to a mysql database and preserve the formatting that the user wants. Essentially the problem is line breaks. When a user inserts data into a text area the text automatically jumps to the next line when the one line fills up with text. Yet when the data is submitted to mysql it doesn't preserve the breaks. I've tried several solutions like the <pre> tag. Basically I want the break that the html textarea creates automatically when it reaches the end of the text area to generate a <br /> tag in my data submission. If anyone can give me a solution I would appreciate it. Thanks. Link to comment https://forums.phpfreaks.com/topic/60131-formatting-form-data/ Share on other sites More sharing options...
AndyB Posted July 16, 2007 Share Posted July 16, 2007 Use nl2br() on the output from the database - http://ca.php.net/manual/en/function.nl2br.php Link to comment https://forums.phpfreaks.com/topic/60131-formatting-form-data/#findComment-299141 Share on other sites More sharing options...
trq Posted July 16, 2007 Share Posted July 16, 2007 asically I want the break that the html textarea creates automatically when it reaches the end of the text area There is no linebreak created automatically, its just the wrapping affect of displaying data within a textarea. You could try using wordwrap when displaying this data back to fake it. Another function to look into would be nl2br, this comes in handy for changing actual linebreaks into <br /> tags. Note: Both these functions should only be applied to your data on the wway out of the database. Store your data in its raw format wherever possible. Link to comment https://forums.phpfreaks.com/topic/60131-formatting-form-data/#findComment-299142 Share on other sites More sharing options...
dbillings Posted July 16, 2007 Author Share Posted July 16, 2007 <pre>Hello This is a test of how this forum handles a pre tag </pre> Link to comment https://forums.phpfreaks.com/topic/60131-formatting-form-data/#findComment-299168 Share on other sites More sharing options...
trq Posted July 16, 2007 Share Posted July 16, 2007 Just place the data with a fixed sized table or better still a div, this really is a html issue, nothing to do with php. Link to comment https://forums.phpfreaks.com/topic/60131-formatting-form-data/#findComment-299172 Share on other sites More sharing options...
dbillings Posted July 16, 2007 Author Share Posted July 16, 2007 This is a test to see if this forum preserves line breaks without using newline or break code. Link to comment https://forums.phpfreaks.com/topic/60131-formatting-form-data/#findComment-299184 Share on other sites More sharing options...
keeB Posted July 16, 2007 Share Posted July 16, 2007 dbillings, basically you have 2 options (yes it always comes down to 2 options it seems) 1. Use a WYSIWYG type Editor and save the contents of that to your DB 2. Do as suggested, save the textarea as normal, and then when you do something like this: <?php $q = "select textarea from myTable where id='1'"; $result = mysql_query($q); $data = mysql_fetch_array($result); print nl2br($data['textarea']); ?> Link to comment https://forums.phpfreaks.com/topic/60131-formatting-form-data/#findComment-299185 Share on other sites More sharing options...
dbillings Posted July 16, 2007 Author Share Posted July 16, 2007 See my above post isn't formated with a div or table. Link to comment https://forums.phpfreaks.com/topic/60131-formatting-form-data/#findComment-299187 Share on other sites More sharing options...
keeB Posted July 16, 2007 Share Posted July 16, 2007 It most certainly used nl2br http://php.net/nl2br or a variation. Here's your post's source: <div class="post"> This is a test<br />to see if this forum <br /><br /> .. etc Link to comment https://forums.phpfreaks.com/topic/60131-formatting-form-data/#findComment-299190 Share on other sites More sharing options...
dbillings Posted July 16, 2007 Author Share Posted July 16, 2007 nl2br doesn't produce the non breaking spaces in the beginning. And a pre html tag will give you a run on sentence unless the user hits return. grrrr. any suggestions for a wysiwyg editor? Link to comment https://forums.phpfreaks.com/topic/60131-formatting-form-data/#findComment-299194 Share on other sites More sharing options...
keeB Posted July 16, 2007 Share Posted July 16, 2007 TinyMCE. To get the non breaking spaces, feel free to write your own function, something like.. <?php function format_output($out) { /* replaces " " with %nbsp (replace with &) */ return nl2br(str_replace (" ", "%nbsp; ", $out)); } ?> Link to comment https://forums.phpfreaks.com/topic/60131-formatting-form-data/#findComment-299198 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.