shamuraq Posted October 19, 2012 Share Posted October 19, 2012 Hi guys, am not very good with regex. I need to replace all double backslashes '\\' in my string into single backslashes '\'. I tried: $pattern = '[\\]'; $replacement = '/\/'; ?> <td width="100%"> <?php echo preg_replace($pattern, $replacement,$q[$i]);?></td> i also tried a few other combinations but the output is either blank or more backslashes are added. Any pointers are appreciated. Thanx in advance. Quote Link to comment https://forums.phpfreaks.com/topic/269696-help-for-preg_replace/ Share on other sites More sharing options...
Christian F. Posted October 19, 2012 Share Posted October 19, 2012 stripslashes () is what you're looking for. Quote Link to comment https://forums.phpfreaks.com/topic/269696-help-for-preg_replace/#findComment-1386488 Share on other sites More sharing options...
Pikachu2000 Posted October 19, 2012 Share Posted October 19, 2012 It looks like the data is coming from a DB query, perhaps? You should check to see if magic_quotes_gpc is on. Quote Link to comment https://forums.phpfreaks.com/topic/269696-help-for-preg_replace/#findComment-1386489 Share on other sites More sharing options...
DavidAM Posted October 19, 2012 Share Posted October 19, 2012 Actually, data from a database or a file is affected by magic_quotes_runtime. While magic_quotes_gpc affects GET, POST, COOKIES, and FILES Quote Link to comment https://forums.phpfreaks.com/topic/269696-help-for-preg_replace/#findComment-1386493 Share on other sites More sharing options...
Pikachu2000 Posted October 19, 2012 Share Posted October 19, 2012 (edited) I was assuming it's being double escaped when it's inserted. It's relatively rare to see _runtime turned on. Good point though. Edited October 19, 2012 by Pikachu2000 Quote Link to comment https://forums.phpfreaks.com/topic/269696-help-for-preg_replace/#findComment-1386496 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.