preg_replace with a " as replace

Associate
Joined
18 Oct 2002
Posts
1,312
Location
Milton Keynes
Hey peeps

Am trying to turn an HTML file into a string (will use file_get_contents()), and then turn all of the "s into \"s so that I can echo the string.

Having problems with what to put in the pattern and what t put in replace

I have
PHP:
$file = file_get_contents("file.html");
$pattern = "\"";
$replacement = "\\\"";
echo preg_replace($pattern, $replacement, $file);

I don't get an output at all, anyone tell me *** i'm doing wrong? Its probably something simple lol :cool:
 
if you are having difficulties in future with escaping regex patterns.. preg_quote() is your friend.

oh, and you need to read up on preg_* functions and regex in general, you are not using delimeters. besides which, str_replace would be better suited for explicit changes.
 
Back
Top Bottom