sonofabear Posted December 30, 2011 Share Posted December 30, 2011 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, ''); Quote Link to comment https://forums.phpfreaks.com/topic/254060-advanced-json-parse-with-php/ Share on other sites More sharing options...
scootstah Posted December 30, 2011 Share Posted December 30, 2011 json_decode? Quote Link to comment https://forums.phpfreaks.com/topic/254060-advanced-json-parse-with-php/#findComment-1302430 Share on other sites More sharing options...
sonofabear Posted December 30, 2011 Author Share Posted December 30, 2011 Yea, I tried that, but it doesn't seem to work, unless I did something wrong... Quote Link to comment https://forums.phpfreaks.com/topic/254060-advanced-json-parse-with-php/#findComment-1302439 Share on other sites More sharing options...
kicken Posted December 30, 2011 Share Posted December 30, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/254060-advanced-json-parse-with-php/#findComment-1302440 Share on other sites More sharing options...
blacknight Posted December 30, 2011 Share Posted December 30, 2011 $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 Quote Link to comment https://forums.phpfreaks.com/topic/254060-advanced-json-parse-with-php/#findComment-1302441 Share on other sites More sharing options...
sonofabear Posted December 30, 2011 Author Share Posted December 30, 2011 Blacknight, thanks that worked great. Now how would I loop through the array years, months, and days to be able to output each date to use like in the example in the original post? Thanks so much! Quote Link to comment https://forums.phpfreaks.com/topic/254060-advanced-json-parse-with-php/#findComment-1302457 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.