keeps21 Posted May 12, 2009 Share Posted May 12, 2009 I'm using the Zend Framewrok 1.8.0, mysql 5.051b and tinymce as the editor. When the data from a textarea is saved into the database each <p> tag is on a newline in the database field. This is how it looks in the database [pre] <p>Paragraph1 this is filler text.</p> <p>Paragraph2 This is filler text.</p> [/pre] This is causing problems when creating a javascript variable from the data in the field as it adds the second paragraph onto the next line in the source code which breaks the script. This is how it looks when assigned to a js variable with tags stripped $nvar = "Paragraph1 this is filler text. Paragraph2 This is filler text." I'm completely stumped as to how to fix it. Link to comment https://forums.phpfreaks.com/topic/157860-unwanted-newline-when-saving-to-database/ Share on other sites More sharing options...
w3evolutions Posted May 12, 2009 Share Posted May 12, 2009 If your not worried about literal format, you can always regexp out any /\s\s+/. Link to comment https://forums.phpfreaks.com/topic/157860-unwanted-newline-when-saving-to-database/#findComment-832653 Share on other sites More sharing options...
The Little Guy Posted May 12, 2009 Share Posted May 12, 2009 Something like this may work for you: $nvar = preg_replace("~\n|\r~",' ',$row['column']); echo $nvar; Link to comment https://forums.phpfreaks.com/topic/157860-unwanted-newline-when-saving-to-database/#findComment-832660 Share on other sites More sharing options...
allworknoplay Posted May 12, 2009 Share Posted May 12, 2009 You should use: strip_tags() function before inputting into the DB then...... Link to comment https://forums.phpfreaks.com/topic/157860-unwanted-newline-when-saving-to-database/#findComment-832665 Share on other sites More sharing options...
keeps21 Posted May 12, 2009 Author Share Posted May 12, 2009 I can't strip the tags out because I need the formatting created in tinymce to be saved into the database to be output. There aren't any \n or \r tags in the database. It's just a case of every new <p> tag in the database text being saved onto a new line. ie like this [pre] <p>Paragraph one, this is text</p> <p>Paragraph two, this paragraph has more text than paragraph one.</p> [/pre] rather than like this [pre] <p>Paragraph one, this is text</p><p>Paragraph two, this paragraph has more text than paragraph one.</p> [/pre] if I could save it to the database the latter way then there'd be no problems. Link to comment https://forums.phpfreaks.com/topic/157860-unwanted-newline-when-saving-to-database/#findComment-832673 Share on other sites More sharing options...
The Little Guy Posted May 12, 2009 Share Posted May 12, 2009 according to your post there are, they are invisible values. \n = new line \r = carriage return. Link to comment https://forums.phpfreaks.com/topic/157860-unwanted-newline-when-saving-to-database/#findComment-832676 Share on other sites More sharing options...
keeps21 Posted May 12, 2009 Author Share Posted May 12, 2009 The problem was with how I had TinyMCE setup. I needed to add the following code to the environment options in the header to prevent it from formatting the source code. apply_source_formatting : false Link to comment https://forums.phpfreaks.com/topic/157860-unwanted-newline-when-saving-to-database/#findComment-832691 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.