Reputation: 1729
I'm writing some JS for a custom API, that has all of its documentation examples as PHP. All good until I hit this example:
$customfields = array(
"11" => "123456",
"12" => "678945"
);
$postfields["customfields"] = base64_encode(serialize($customfields));
So I get that I am probably doing something like btoa(JSON.stringify(x))
- but what's tricky is that I assume the server, when it decodes and deserialises, will expect to have something it recognises as a PHP value. Would anyone be able to explain how I get prepare this base64 encoded, serialized data in JS, so the PHP server will be happy with it when it arrives?
Upvotes: 0
Views: 51
Reputation: 1039
You could try https://locutus.io/php/var/serialize/ which looks like it will do what you need for the serialize part. You'd create the customfields as an object then pass it to the above mentioned serialize function then base 64 encode that result.
Upvotes: 1