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. 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. 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. 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 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 I was assuming it's being double escaped when it's inserted. It's relatively rare to see _runtime turned on. Good point though. Link to comment https://forums.phpfreaks.com/topic/269696-help-for-preg_replace/#findComment-1386496 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.