I\'m trying to mimic the json_encode bitmask flags implemented in PHP 5.3.0, here is the string I have:
json_encode
$s = addslashes(\'O\\\'Rei\"lly\'); // O
It's escaping the backslash as well as the quote. It's difficult dealing with escaped escapes, as you're doing here, as it quickly turns into backslash counting games. :-/