i believe devin already answered this?
Or are you getting confused by the errors you see after posting a message?
In any case,
to transform ' to \', use:
$newvalue = addslashes($oldvalue);
to transform \' to ', use:
$newvalue = stripslashes($oldvalue);
-sridhar