I'm having some strange issues with decoding an XML snippet, contained with a cookie, with PHP's base64_decode function:
As soon as we try running the same code in the browser, the decoded XML appears to contain loads of UTF-16 characters interspersed with fragments of the expected XML tags. For example:
<CreateSession\u000f\u0013Y...
As you might then expect, we end up with an Exception: String could not be parsed as XML... error when passing this string to the SimpleXMLElement constructor.
Some further info:
Has anyone come across anything like this before or have any idea what might be causing this?
Aha! It turns out that, when run in the browser, the cookie values were automatically URL decoded by PHP, meaning that any '+' in the base64 encoded text were being replaced by spaces. Adding this line of code before calling base64_decode
fixed things:
$tmp = str_replace(' ', '+', $value);