Jump to content

Recommended Posts

Hello, I am a novice with php and know close to nothing about JSON. I am using wordpress and have 2 calendar type plugins I want to work together. With one plugin the user inputs dates that they are booked. The other plugin is a date picker, the cool part is it allows you to black out dates using php before the date picker is built.

 

So what I'm trying to do is get the data from what the user chose as booked, and not let a user on the front end pick any of the booked dates with the date picker. Hope that makes sense. The problem is the formatting of the data with the date booked plugin. This is what is in the field

 

a:1:{s:9:"calendars";a:1:{i:1;a:4:{s:12:"calendarName";s:21:"Availability Calendar";s:12:"calendarJson";s:59:"{"year2011":{"month12":{"day25":"booked","day6":"booked"}}}";s:11:"dateCreated";i:1324333825;s:12:"dateModified";i:1324333825;}}}

 

 

I chose 2 dates to be booked in that example: dec 25 2011, and dec 6 2011.  I have no idea how I would parse the above data into what I need. I don't really need the data from the other parts of the above code, just the dates. The others are field descriptions and etc. that wordpress uses.

 

Incidentally, this is what the date picker setup would look like in the above senario:

 

$myCalendar->setSpecificDate(array("2011-12-06","2011-12-25"), 0, '');

Link to comment
https://forums.phpfreaks.com/topic/254060-advanced-json-parse-with-php/
Share on other sites

What you pasted is not JSON.  It is a string of serialized data, and you can reverse it using unserialize.

 

After you unserialize it you can access the key 'calendarJson' which contains json and you can decode that using json_decode.

$data = 'a:1:{s:9:"calendars";a:1:{i:1;a:4:{s:12:"calendarName";s:21:"Availability Calendar";s:12:"calendarJson";s:59:"{"year2011":{"month12":{"day25":"booked","day6":"booked"}}}";s:11:"dateCreated";i:1324333825;s:12:"dateModified";i:1324333825;}}}';
$x = @unserialize($data);
echo '<pre>';
print_r($x);
$a = json_decode($x['calendars']['1']['calendarJson'],true);
print_r($a);

 

this worked on my server unserialize is php 4.3 i think

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.