siwelis Posted March 2, 2010 Share Posted March 2, 2010 I'm getting 3 slashes when I use mysql_real_escape_string and then when I use stripslashes nothing happens. I still have 3 slashes. I turned off mysql_real... And am still getting a preceding slash, leading me to believe it's a server/php setting... However, stripslashes still does nothing so my sentences all look like this to users: That\'s a great Joe's BBQ sandwhich! Any advice is appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/193932-why-am-im-getting-3-slashes-and-cant-stripslash-them/ Share on other sites More sharing options...
ferdi Posted March 2, 2010 Share Posted March 2, 2010 Well, what's the input you want the slashes removed from? Please give an example, and how you would like it to be. Quote Link to comment https://forums.phpfreaks.com/topic/193932-why-am-im-getting-3-slashes-and-cant-stripslash-them/#findComment-1020583 Share on other sites More sharing options...
siwelis Posted March 2, 2010 Author Share Posted March 2, 2010 I want it to be like this when outputted: That's a great Joe's BBQ sandwhich! No slashes (of course, unless someone put them in there). I assume I can just make my own function str_replace("\'", "'", $string); but I still don't get why stripslashes isn't working... I hate to make a workaround when I could potentially fix the problem at its root. I did some research and found magic_quotes_sybase being on will disable stripslashes normal function and make it replace double stacked apostrophes '' but sybase is OFF. Quote Link to comment https://forums.phpfreaks.com/topic/193932-why-am-im-getting-3-slashes-and-cant-stripslash-them/#findComment-1020585 Share on other sites More sharing options...
PFMaBiSmAd Posted March 2, 2010 Share Posted March 2, 2010 It would help if you described the flow of data and at what point it has the excess slashes. However, the problem is likely due to magic_quotes_gpc (escapes GET, POST, and COOKIE data, even if you don't want them to be) and magic_quotes_runtime (escapes data retrieved from databases and files, even if you don't want them to be.) If your data is escaped correctly, a single time by mysql_real_escape_string(), the actual \ should not be present in your table (unless someone had a \ as part of the data.) This will help you pin down if the problem is occurring when the data is being input or when it is being retrieved. If you cannot turn off the magic_quotes_gpc setting, you would then need to use stripslashes() if magic_quotes_gpc is ON to remove the escape characters before you use mysql_real_escape_string(). You should not unconditionally use stripslashes() because that would prevent any actual \ in the data when magic_quotes_gpc is OFF. Quote Link to comment https://forums.phpfreaks.com/topic/193932-why-am-im-getting-3-slashes-and-cant-stripslash-them/#findComment-1020586 Share on other sites More sharing options...
siwelis Posted March 2, 2010 Author Share Posted March 2, 2010 The excess slashes appear to have been due to my use of mysql_real_escape_string. I removed its usage until the next PHP upgrade. stripslashes wasn't working because I was using it in the wrong place (on the right variable, but a similar looking location in the file). Thank you for your help! Quote Link to comment https://forums.phpfreaks.com/topic/193932-why-am-im-getting-3-slashes-and-cant-stripslash-them/#findComment-1020603 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.