my string is
$str = '<img src="\"images/hai.jpg\"" alt="" /> Text <img src="\"images/hai.jpg\"" alt="" />';
i want to remove all \" from the string.
I think you aren't looking for a regex, but for the stripslashes($str) method.
EDIT: From the comments, I understand that you will only replace \" with nothing, you should use a simple str_replace here, as @Gumbo said:
$str = ...;
$newStr = str_replace('\"', '', $str);
echo $newStr;
You can use regular expressions for this, but the pReg library isn't fast, if you can find a str_* or array variant which does the same I always recommend to use that instead of preg_*
This looks like the sort of data string that has been through more than one escape sequence. You might want to look for the underlying cause of the backslashes and duplicated quotes. In PHP, magic quotes can cause this sort of thing. If you can get to this article it will explain the issues.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_6630-Magic-Quotes-a-bad-idea-from-day-one.html
HTH, ~Ray
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With