views:

38

answers:

1

I'm trying to replace \' with ' but it won't work

This is the text I want to replace from

Using Twitter\'s @Anywhere Service in 6 Steps

and this is the code

$tutorial = "Using Twitter\'s @Anywhere Service in 6 Steps ";
echo $tutorial."<br /><br />";
$tut_title = preg_replace("/\\'/", "'", $tutorial);
echo $tut_title; 
+2  A: 

You don't need to bother with regular expressions for this. In this particular case, you can just use stripslashes.

You can also use str_replace("\\'", "'", $tutorial);

For future regex reference, though, you would need to double-escape the backslash:

$tut_title = preg_replace("/\\\\'/", "'", $tutorial);

Why? because in your current form, you're passing the pattern /\'/ to the regex engine, which is just trying to escape '

Matt
thank you for your help :)
krike
Yeah, use this approach, though for some reason, the output looked like it was working in my last answer. Sorry about that.
SoLoGHoST
ok :D thanks anyway for your help
krike