wigglesby Posted January 13, 2010 Share Posted January 13, 2010 Hi I have some data in my db, which is inserted into a form. As some of the text is in " it's " with single quote, it inserts with a \' into the db. This is all fine, the problem is I'm wanting to use nl2br, which finds all the \r\n and outputs a break. But this still outputs the it\'s string. I have the following: $json_out = nl2br(stripslashes($mtj->get_json())); But using stripslashes removes the \ form the it\'s but then outputs the rn minus theri slashes. Anyway I can round this? Thanks Link to comment https://forums.phpfreaks.com/topic/188316-nl2br/ Share on other sites More sharing options...
ignace Posted January 13, 2010 Share Posted January 13, 2010 $json_out = stripslashes(nl2br($mtj->get_json())); Link to comment https://forums.phpfreaks.com/topic/188316-nl2br/#findComment-994125 Share on other sites More sharing options...
trq Posted January 13, 2010 Share Posted January 13, 2010 If you are having backslashes inserted into your database your data is not being escaped properly. You should check if magic quotes is enabled, and if it is strip all slashes from your data then apply mysql_real_escape_string to it prior to placing it within your database. Link to comment https://forums.phpfreaks.com/topic/188316-nl2br/#findComment-994126 Share on other sites More sharing options...
wigglesby Posted January 13, 2010 Author Share Posted January 13, 2010 Ok, I'm using: $content = mysql_real_escape_string($_POST['content']); To insert the text. Do I need to add stripslashes before the real_escape_string function? $content = stripslasges(mysql_real_escape_string($_POST['content'])); The code: $json_out = stripslashes(nl2br($mtj->get_json())); didn't work Thanks Link to comment https://forums.phpfreaks.com/topic/188316-nl2br/#findComment-994148 Share on other sites More sharing options...
trq Posted January 13, 2010 Share Posted January 13, 2010 Ok, I'm using: $content = mysql_real_escape_string($_POST['content']); To insert the text. Do I need to add stripslashes before the real_escape_string function? If magic quotes are enabled, yes. if (get_magic_quotes_gpc()) { $content = stripslashes($_POST['content']); } else { $content = $_POST['content']; } $content = mysql_real_escape_string($content); Link to comment https://forums.phpfreaks.com/topic/188316-nl2br/#findComment-994149 Share on other sites More sharing options...
Adam Posted January 13, 2010 Share Posted January 13, 2010 Sounds like you may have magic quotes turned on. What does get_magic_quotes_gpc return? -- thorpe beat me too it, kinda. I think your best bet would be to disable, if it is enabled, it to be honest. Link to comment https://forums.phpfreaks.com/topic/188316-nl2br/#findComment-994151 Share on other sites More sharing options...
wigglesby Posted January 13, 2010 Author Share Posted January 13, 2010 Ok: echo get_magic_quotes_gpc(); Returned 1, so I guess magic quotes is turned on.... $json_out = nl2br($mtj->get_json()); This seemed to work as well. Cheers guys Link to comment https://forums.phpfreaks.com/topic/188316-nl2br/#findComment-994154 Share on other sites More sharing options...
wigglesby Posted January 13, 2010 Author Share Posted January 13, 2010 Ok, so it works for some but not others: if (get_magic_quotes_gpc()) { $good_practice = stripslashes($_POST['good_practice']); $investment_return = stripslashes($_POST['investment_return']); } else { $good_practice = $_POST['good_practice']; $investment_return = $_POST['investment_return']; } $good_practice = mysql_real_escape_string($_POST['good_practice']); $investment_return = mysql_real_escape_string($_POST['investment_return']); On output it will still output the following: it\'s Any idea why? Thanks Link to comment https://forums.phpfreaks.com/topic/188316-nl2br/#findComment-994164 Share on other sites More sharing options...
Adam Posted January 13, 2010 Share Posted January 13, 2010 Should be: $good_practice = mysql_real_escape_string($good_practice); $investment_return = mysql_real_escape_string($investment_return); Link to comment https://forums.phpfreaks.com/topic/188316-nl2br/#findComment-994168 Share on other sites More sharing options...
wigglesby Posted January 13, 2010 Author Share Posted January 13, 2010 Oh yeah Cheers everyone! Link to comment https://forums.phpfreaks.com/topic/188316-nl2br/#findComment-994174 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.