orange08 Posted May 7, 2009 Share Posted May 7, 2009 hi, i'm using textarea for user to key in their paragraph of text, then save those paragraphs to database. now, i'm having problem to display those text in correct alignment with simple echo command... for example: i saved three paragraphs of text into database...but, when i display them in a table with this code <table><tr> <td><?php echo $myparagraph; ?></td> </tr></table> but, all the paragraphs will be displayed joined together, and the blank line will be ignored too... so, i would like to know how can i solve this problem, please? Quote Link to comment https://forums.phpfreaks.com/topic/157216-display-paragraph-of-text-save-to-database-through-textarea/ Share on other sites More sharing options...
Yesideez Posted May 7, 2009 Share Posted May 7, 2009 http://uk3.php.net/nl2br Quote Link to comment https://forums.phpfreaks.com/topic/157216-display-paragraph-of-text-save-to-database-through-textarea/#findComment-828386 Share on other sites More sharing options...
orange08 Posted May 7, 2009 Author Share Posted May 7, 2009 http://uk3.php.net/nl2br ya, i have tested with this function before by this code $myparagraphs = nl2br($myparagraphs); echo $myparagraphs; but, got one problem, when my entry of text got single or double quote(', ") then the output got backslash \ so how can i solve this? thanks! Quote Link to comment https://forums.phpfreaks.com/topic/157216-display-paragraph-of-text-save-to-database-through-textarea/#findComment-828393 Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 stripslashes Quote Link to comment https://forums.phpfreaks.com/topic/157216-display-paragraph-of-text-save-to-database-through-textarea/#findComment-828442 Share on other sites More sharing options...
premiso Posted May 7, 2009 Share Posted May 7, 2009 but, got one problem, when my entry of text got single or double quote(', ") then the output got backslash \ so how can i solve this? Your input system is double escaping. As ken mentioned stripslashes will solve this. But if you post anything with slashes they tend to get removed. I would fix your database entry part as you are either addslashes to the data (which is wrong btw) or you are mysql_real_escape_string (which is what you should use) but while Magic Quotes are turned on, which would cause a double escape as well. If Magic Quotes are on I would suggest turning them off and that should prevent the double escaping without any code modification. However, if you do use addslashes I would suggest using the mysql function instead, as it escapes just for the mysql DB and will catch items that addslashes will not. Quote Link to comment https://forums.phpfreaks.com/topic/157216-display-paragraph-of-text-save-to-database-through-textarea/#findComment-828512 Share on other sites More sharing options...
orange08 Posted May 7, 2009 Author Share Posted May 7, 2009 but, got one problem, when my entry of text got single or double quote(', ") then the output got backslash \ so how can i solve this? Your input system is double escaping. As ken mentioned stripslashes will solve this. But if you post anything with slashes they tend to get removed. I would fix your database entry part as you are either addslashes to the data (which is wrong btw) or you are mysql_real_escape_string (which is what you should use) but while Magic Quotes are turned on, which would cause a double escape as well. If Magic Quotes are on I would suggest turning them off and that should prevent the double escaping without any code modification. However, if you do use addslashes I would suggest using the mysql function instead, as it escapes just for the mysql DB and will catch items that addslashes will not. i have read a few times your explanation, but not too sure whether i really get it or not. as your suggestion, i'll display my paragraph like this: echo nl2br(stripslashes($row['myparagraph'])); but, as you have mentioned, when i post something with slashes, the slash will be removed. so, how can i solve this? is that you meant i can use mysql_real_escape_string when the entry is saved to database? and how can i know whether Magic Quotes is turn on or off? thanks! Quote Link to comment https://forums.phpfreaks.com/topic/157216-display-paragraph-of-text-save-to-database-through-textarea/#findComment-828617 Share on other sites More sharing options...
premiso Posted May 7, 2009 Share Posted May 7, 2009 Post the code where the data is entered into the DB. and how can i know whether Magic Quotes is turn on or off? get_magic_quotes_gpc if that returns true magic quote are on, if false they are off. Quote Link to comment https://forums.phpfreaks.com/topic/157216-display-paragraph-of-text-save-to-database-through-textarea/#findComment-828637 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.