Mirko Di Lucia
Mirko Di Lucia

Reputation: 13

String format from Woocommerce RESTful API

I'm currently working with woo-commerce RESTful API and booking plugin.

I need to parse this string from the "_wc_booking_availability" JSON field.

a:1:{i:0;a:5:{s:4:"type";s:6:"custom";s:8:"bookable";s:3:"yes";s:8:"priority";i:10;s:4:"from";s:10:"2019-12-11";s:2:"to";s:10:"2020-03-26";}}

But I can't understand which format is. Seem JSON but also contain other elements.

Upvotes: 1

Views: 142

Answers (1)

Sakti Behera
Sakti Behera

Reputation: 76

This is a serialized string, use PHP unserialize() method, which will return an array like below.

$serializedStr = 'a:1:{i:0;a:5:{s:4:"type";s:6:"custom";s:8:"bookable";s:3:"yes";s:8:"priority";i:10;s:4:"from";s:10:"2019-12-11";s:2:"to";s:10:"2020-03-26";}}';
$unserializeOutput = unserialize($serializedStr);
print_r($unserializeOutput)

Array
(
    [0] => Array
        (
            [type] => custom
            [bookable] => yes
            [priority] => 10
            [from] => 2019-12-11
            [to] => 2020-03-26
        )

)

Upvotes: 1

Related Questions