Thanks, Now it makes sense.
I won't do this with ereg_replace. preg_replace offers a much more sophisticated syntax - you can do things with two characters in PCRE regexps that require exponentially long POSIX regexps.
Okay, so we don't mess with the the two end \" sequences, but we replace all the other \" sequences in between with \\".
If you could get the regexps right it could be done in three lines - the first to turn all \" into \\" and then two regexps to change the ones on the end back. I had a crack but kept losing count.
It could be done, but I still maintain it would be less eye-twisting to do it without regexps. (At least, I got this working):
$b = chr(92);
if(strpos($string,$b.'"')!==false) // Why bother, otherwise?
{ $string = str_replace($b.'"',"$b$b$b".'"',$string);
$left = strpos($string, "$b$b$b".'"');
$string = substr($string, 0, $left).substr($string,$left+2);
$string = strrev($string);
$right = strpos($string, '"'."$b$b$b");
$string = substr($string, 0, $right+2).substr($string, $right+4);
$string = strrev($string);
}
You'll note I went to some lengths to avoid having to use literal backslashes at all.