TeamStar TeamStar - 1 year ago 187
PHP Question

PHP preg_replace backslash

I have double backslashes '\' in my string that needs to be converted into single backslashes '\'. I've tried several combinations and end up with the whole string disappearing when I used echo or more backslashes are added to the string by accident. This regex thing is making me go

I tried this amongst other failed attempts:

$pattern = '[\\]';
$replacement = '/\/';

<td width="100%">&nbsp;<?php echo preg_replace($pattern, $replacement,$q[$i]);?></td>

I do apologise if this is a foolish issue and I appreciate any pointers.

Answer Source

Use stripslashes() - it does exactly what you're looking for.

<td width="100%">&nbsp;<?php echo stripslashes($q[$i]);?></td>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download