Umm.. I am not sure about preg_replace. But you can do the same with str_replace!
<?php
$txt="' is a single quote \" is a double quote.I want to replace ' with \' and \" with \" ";
echo "Actual text: " .$txt."<br />";
$x=str_replace('"','\"',str_replace("'","\'",$txt));
echo "Replaced text: ". $x;
?>
Hope it helps!
Naveen