简体   繁体   中英

Unserialize from WP database, booking dates

i have the next info stored in a wp table

a:83:{i:0;s:0:"";s:10:"hotel_name";s:10:"Casa Coral";s:13:"hotel_address";s:39:"Constanta, Mamaia Nord, Str. D2, Nr. 28";s:14:"hotel_locality";s:22:"Constanta, Mamaia Nord";s:15:"hotel_telephone";s:12:"0728.330.713";s:11:"hotel_email";s:19:"office@vilacoral.ro";s:13:"hotel_checkin";a:2:{s:4:"from";s:2:"15";s:2:"to";s:2:"16";}s:14:"hotel_checkout";a:2:{s:4:"from";s:2:"11";s:2:"to";s:2:"12";}s:18:"hotel_pets_message";s:16:"Pets are allowed";s:12:"listing_page";s:2:"12";s:12:"booking_page";s:2:"13";s:20:"reservation_received";s:20:"reservation-received";s:12:"pay_endpoint";s:15:"pay-reservation";s:8:"currency";s:3:"IDR";s:17:"currency_position";s:5:"after";s:19:"thousands_separator";s:1:",";s:17:"decimal_separator";s:1:".";s:14:"room_size_unit";s:3:"m²";s:15:"listing_sorting";s:5:"title";s:18:"low_room_threshold";i:1;s:23:"room_catalog_image_size";a:3:{s:5:"width";i:480;s:6:"height";i:294;s:4:"crop";i:1;}s:22:"room_single_image_size";a:3:{s:5:"width";i:1140;s:6:"height";i:699;s:4:"crop";i:1;}s:25:"room_thumbnail_image_size";a:3:{s:5:"width";i:85;s:6:"height";i:85;s:4:"crop";i:1;}s:13:"room_lightbox";s:1:"1";s:12:"booking_mode";s:14:"manual-booking";s:30:"booking_additional_information";s:1:"1";s:22:"booking_minimum_nights";i:1;s:20:"booking_hold_minutes";i:120;s:35:"hide_disabled_dates_from_datepicker";s:1:"1";s:34:"allow_checkout_first_disabled_date";s:1:"1";s:16:"payment_gateways";a:1:{s:6:"paypal";s:1:"1";}s:15:"default_gateway";s:6:"paypal";s:14:"paypal_message";s:54:"Pay with PayPal - The safer, easier way to pay online!";s:14:"stripe_message";s:45:"Pay with your credit or debit card via Stripe";s:19:"emails_admin_notice";s:19:"office@vilacoral.ro";s:16:"emails_from_name";s:10:"Casa Coral";s:25:"emails_from_email_address";s:19:"office@vilacoral.ro";s:11:"emails_type";s:4:"html";s:11:"emails_logo";s:55:"http://vilacoral.ro/wp-content/uploads/2017/05/logo.png";s:18:"emails_footer_text";s:58:"Termeni si conditii: www.vilacoral.ro/termeni-si-conditii/";s:30:"emails_new_reservation_enabled";s:1:"1";s:30:"emails_new_reservation_subject";s:51:"{site_title} - Rezervare noua #{reservation_number}";s:30:"emails_new_reservation_heading";s:14:"Rezervare noua";s:31:"emails_request_received_enabled";s:1:"1";s:31:"emails_request_received_subject";s:35:"Rezervarea dvs. pentru {site_title}";s:31:"emails_request_received_heading";s:14:"Cerere primita";s:36:"emails_confirmed_reservation_enabled";s:1:"1";s:36:"emails_confirmed_reservation_subject";s:35:"Rezervarea dvs. pentru {site_title}";s:36:"emails_confirmed_reservation_heading";s:29:"Va multumim pentru rezervare!";s:28:"emails_guest_invoice_subject";s:46:"Factura pentru rezervare #{reservation_number}";s:28:"emails_guest_invoice_heading";s:46:"Factura pentru rezervare #{reservation_number}";s:36:"emails_cancelled_reservation_enabled";s:1:"1";s:36:"emails_cancelled_reservation_subject";s:54:"{site_title} - Rezervare anulata #{reservation_number}";s:36:"emails_cancelled_reservation_heading";s:17:"Rezervare anulata";s:42:"emails_guest_cancelled_reservation_enabled";s:1:"1";s:42:"emails_guest_cancelled_reservation_subject";s:35:"Rezervarea dvs. pentru {site_title}";s:42:"emails_guest_cancelled_reservation_heading";s:17:"Rezervare anulata";s:22:"seasonal_prices_schema";a:37:{i:1;a:3:{s:4:"from";s:10:"2017-05-11";s:2:"to";s:10:"2017-05-12";s:5:"index";s:1:"1";}i:2;a:3:{s:4:"from";s:10:"2017-05-13";s:2:"to";s:10:"2017-05-14";s:5:"index";s:1:"2";}i:3;a:3:{s:4:"from";s:10:"2017-05-15";s:2:"to";s:10:"2017-05-19";s:5:"index";s:1:"3";}i:4;a:3:{s:4:"from";s:10:"2017-05-20";s:2:"to";s:10:"2017-05-21";s:5:"index";s:1:"4";}i:5;a:3:{s:4:"from";s:10:"2017-05-22";s:2:"to";s:10:"2017-05-26";s:5:"index";s:1:"5";}i:6;a:3:{s:4:"from";s:10:"2017-05-27";s:2:"to";s:10:"2017-05-28";s:5:"index";s:1:"6";}i:7;a:3:{s:4:"from";s:10:"2017-05-29";s:2:"to";s:10:"2017-06-02";s:5:"index";s:1:"7";}i:8;a:3:{s:4:"from";s:10:"2017-06-03";s:2:"to";s:10:"2017-06-04";s:5:"index";s:1:"8";}i:9;a:3:{s:4:"from";s:10:"2017-06-05";s:2:"to";s:10:"2017-06-09";s:5:"index";s:1:"9";}i:10;a:3:{s:4:"from";s:10:"2017-06-10";s:2:"to";s:10:"2017-06-11";s:5:"index";s:2:"10";}i:11;a:3:{s:4:"from";s:10:"2017-06-12";s:2:"to";s:10:"2017-06-16";s:5:"index";s:2:"11";}i:12;a:3:{s:4:"from";s:10:"2017-06-17";s:2:"to";s:10:"2017-06-18";s:5:"index";s:2:"12";}i:13;a:3:{s:4:"from";s:10:"2017-06-19";s:2:"to";s:10:"2017-06-23";s:5:"index";s:2:"13";}i:14;a:3:{s:4:"from";s:10:"2017-06-24";s:2:"to";s:10:"2017-06-25";s:5:"index";s:2:"14";}i:15;a:3:{s:4:"from";s:10:"2017-06-26";s:2:"to";s:10:"2017-06-30";s:5:"index";s:2:"15";}i:16;a:3:{s:4:"from";s:10:"2017-07-01";s:2:"to";s:10:"2017-07-02";s:5:"index";s:2:"16";}i:17;a:3:{s:4:"from";s:10:"2017-07-03";s:2:"to";s:10:"2017-07-07";s:5:"index";s:2:"17";}i:18;a:3:{s:4:"from";s:10:"2017-07-08";s:2:"to";s:10:"2017-07-09";s:5:"index";s:2:"18";}i:19;a:3:{s:4:"from";s:10:"2017-07-10";s:2:"to";s:10:"2017-07-14";s:5:"index";s:2:"19";}i:20;a:3:{s:4:"from";s:10:"2017-07-15";s:2:"to";s:10:"2017-07-16";s:5:"index";s:2:"20";}i:21;a:3:{s:4:"from";s:10:"2017-07-17";s:2:"to";s:10:"2017-07-21";s:5:"index";s:2:"21";}i:22;a:3:{s:4:"from";s:10:"2017-07-22";s:2:"to";s:10:"2017-07-23";s:5:"index";s:2:"22";}i:23;a:3:{s:4:"from";s:10:"2017-07-24";s:2:"to";s:10:"2017-07-28";s:5:"index";s:2:"23";}i:24;a:3:{s:4:"from";s:10:"2017-07-29";s:2:"to";s:10:"2017-07-30";s:5:"index";s:2:"24";}i:25;a:3:{s:4:"from";s:10:"2017-07-31";s:2:"to";s:10:"2017-08-04";s:5:"index";s:2:"25";}i:26;a:3:{s:4:"from";s:10:"2017-08-05";s:2:"to";s:10:"2017-08-06";s:5:"index";s:2:"26";}i:27;a:3:{s:4:"from";s:10:"2017-08-07";s:2:"to";s:10:"2017-08-11";s:5:"index";s:2:"27";}i:28;a:3:{s:4:"from";s:10:"2017-08-12";s:2:"to";s:10:"2017-08-13";s:5:"index";s:2:"28";}i:29;a:3:{s:4:"from";s:10:"2017-08-14";s:2:"to";s:10:"2017-08-18";s:5:"index";s:2:"29";}i:30;a:3:{s:4:"from";s:10:"2017-08-19";s:2:"to";s:10:"2017-08-20";s:5:"index";s:2:"30";}i:31;a:3:{s:4:"from";s:10:"2017-08-21";s:2:"to";s:10:"2017-08-25";s:5:"index";s:2:"31";}i:32;a:3:{s:4:"from";s:10:"2017-08-26";s:2:"to";s:10:"2017-08-27";s:5:"index";s:2:"32";}i:33;a:3:{s:4:"from";s:10:"2017-08-28";s:2:"to";s:10:"2017-09-01";s:5:"index";s:2:"33";}i:34;a:3:{s:4:"from";s:10:"2017-09-02";s:2:"to";s:10:"2017-09-03";s:5:"index";s:2:"34";}i:35;a:3:{s:4:"from";s:10:"2017-09-04";s:2:"to";s:10:"2017-09-08";s:5:"index";s:2:"35";}i:36;a:3:{s:4:"from";s:10:"2017-09-09";s:2:"to";s:10:"2017-09-10";s:5:"index";s:2:"36";}i:37;a:3:{s:4:"from";s:10:"2017-09-11";s:2:"to";s:10:"2018-02-28";s:5:"index";s:2:"37";}}s:22:"booking_months_advance";i:0;s:20:"booking_arrival_date";i:0;s:22:"booking_maximum_nights";i:0;s:21:"disabled_dates_schema";a:0:{}s:27:"room_unavailable_visibility";i:0;s:14:"paypal_sandbox";s:1:"1";s:20:"hotel_accepted_cards";a:4:{s:10:"mastercard";s:1:"1";s:4:"visa";s:1:"1";s:7:"maestro";s:1:"1";s:6:"visa_e";s:1:"1";}s:12:"paypal_email";s:0:"";s:17:"paypal_page_style";s:0:"";s:17:"stripe_form_image";s:0:"";s:22:"stripe_live_secret_key";s:0:"";s:27:"stripe_live_publishable_key";s:0:"";s:22:"stripe_test_secret_key";s:0:"";s:27:"stripe_test_publishable_key";s:0:"";s:10:"paypal_log";i:0;s:15:"stripe_testmode";i:0;s:10:"stripe_log";i:0;s:10:"terms_page";s:3:"521";s:28:"emails_guest_invoice_enabled";i:0;s:14:"hotel_postcode";s:0:"";s:9:"hotel_fax";s:0:"";s:18:"price_num_decimals";i:0;s:10:"hotel_pets";i:0;s:19:"enforce_ssl_booking";i:0;s:19:"unforce_ssl_booking";i:0;}

And when i try to print dates as a table i get an error using:

while($row = mysqli_fetch_array($result)){

    $mydata = $row['option_value'];
    $data = unserialize($mydata);
    $tabel = $data['seasonal_prices_schema'];
    foreach($tabel as $linie) {

        $from = $linie['from'];
        $to = $linie['to'];

        echo '<tr>';
        echo '<td>' . $from . '</td>';
        echo '<td>' . $to . '</td>';
        echo '</tr>';

    }

}

The error is: Warning: Invalid argument supplied for foreach() in x.php on line 102

-> foreach($tabel as $linie)

When i paste the following stored dates into $mydata = ''; it prints it, but when i've put the info from db isnt working.

Sorry for my english, if you have any idea.

EDIT:

I think i figured why isnt working, first of all it dosnt sees it as an array if it gets it from data base, if i copy paste from database on $mydata it prints the table. I think the problem is s:3:"m²"; that "2".

THE FIX: I've put this after making connection to DB. and fixed the problem with the "m²"

if($link->set_charset("utf8")){
   // rest of the code
}

Thanks

Well that is simple to explain here. Your string is: s:22:"seasonal_p... , what says: String with 22 charackters and content ...

So that is not an array you can loop over.

To unserialize an array, your string must start with: a:32:{s:22:...} , so in this case the strign in the database might be currupted.

Just try https://de.functions-online.com/unserialize.html with your string posted and you will see that it just returns a string.

By the way: The unserialize function returns false in case of an error. So you cannot distiguish between:

$val = unserialize(serialize(false));

and

$val = unserialize('##'); //invalid string

UPDATE

Again, looking at the result reveals what happens: Now you are unserializing an array, but that is deeply nested and contains other arrays with either numeric or string keys, so you cannot use an array as string.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM