If that test script doesn't work for you, then I'm stumped.
I guess you could do this:
$text = 'Test \\\' " string';
$symbols = array("'",'"');
for ($i = 0; $i < strlen($text); $i++) {
if (in_array($text[$i], $symbols)) {
$text[$i] = '`';
}
}
echo $text;
(Again, with a backslash before "'" in $text.)